Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add @Mapper annotation #198

Open
wants to merge 1 commit into
base: 1.3.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions src/main/java/org/mybatis/spring/annotation/Mapper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* Copyright 2010-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.mybatis.spring.annotation;

import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import java.lang.annotation.Documented;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

/**
* Marker interface for indicate the MyBatis mapper.
*
* @author Kazuki Shimizu
* @since 1.3.2
*/
@Documented
@Inherited
@Retention(RUNTIME)
@Target(TYPE)
public @interface Mapper {
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2010-2016 the original author or authors.
* Copyright 2010-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -37,7 +37,6 @@
import org.springframework.beans.factory.support.GenericBeanDefinition;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import com.mockrunner.mock.jdbc.MockDataSource;

Expand Down Expand Up @@ -257,12 +256,12 @@ public static class AppConfigWithMarkerInterface {
}

@Configuration
@MapperScan(basePackages = "org.mybatis.spring.mapper", annotationClass = Component.class)
@MapperScan(basePackages = "org.mybatis.spring.mapper", annotationClass = Mapper.class)
public static class AppConfigWithAnnotation {
}

@Configuration
@MapperScan(basePackages = "org.mybatis.spring.mapper", annotationClass = Component.class, markerInterface = MapperInterface.class)
@MapperScan(basePackages = "org.mybatis.spring.mapper", annotationClass = Mapper.class, markerInterface = MapperInterface.class)
public static class AppConfigWithMarkerInterfaceAndAnnotation {
}

Expand Down
4 changes: 2 additions & 2 deletions src/test/java/org/mybatis/spring/config/annotation.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--

Copyright 2010-2016 the original author or authors.
Copyright 2010-2017 the original author or authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -32,5 +32,5 @@
<!-- Scan for mappers and let them be autowired; notice there is no
UserDaoImplementation needed. The required SqlSessionFactory will be
autowired. -->
<mybatis:scan base-package="org.mybatis.spring.mapper" annotation="org.springframework.stereotype.Component"/>
<mybatis:scan base-package="org.mybatis.spring.mapper" annotation="org.mybatis.spring.annotation.Mapper"/>
</beans>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--

Copyright 2010-2016 the original author or authors.
Copyright 2010-2017 the original author or authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -34,5 +34,5 @@
autowired. -->
<mybatis:scan base-package="org.mybatis.spring.mapper"
marker-interface="org.mybatis.spring.mapper.MapperInterface"
annotation="org.springframework.stereotype.Component" />
annotation="org.mybatis.spring.annotation.Mapper" />
</beans>
6 changes: 3 additions & 3 deletions src/test/java/org/mybatis/spring/mapper/AnnotatedMapper.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2010-2016 the original author or authors.
* Copyright 2010-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,11 +15,11 @@
*/
package org.mybatis.spring.mapper;

import org.springframework.stereotype.Component;
import org.mybatis.spring.annotation.Mapper;

// annotated interface for MapperScannerPostProcessor tests
// ensures annotated classes are loaded
@Component
@Mapper
public interface AnnotatedMapper {
public void method();
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2010-2016 the original author or authors.
* Copyright 2010-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,10 +15,10 @@
*/
package org.mybatis.spring.mapper;

import org.springframework.stereotype.Component;
import org.mybatis.spring.annotation.Mapper;

// annotated interface for MapperScannerPostProcessor tests
// ensures annotated class with no methods is not loaded
@Component
@Mapper
public interface AnnotatedMapperZeroMethods {
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2010-2016 the original author or authors.
* Copyright 2010-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -27,6 +27,7 @@
import org.junit.Test;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.SqlSessionTemplate;
import org.mybatis.spring.annotation.Mapper;
import org.mybatis.spring.mapper.child.MapperChildInterface;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.config.BeanDefinition;
Expand All @@ -36,7 +37,6 @@
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.GenericBeanDefinition;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.stereotype.Component;

import com.mockrunner.mock.jdbc.MockDataSource;

Expand Down Expand Up @@ -128,7 +128,7 @@ public void testMarkerInterfaceScan() {
@Test
public void testAnnotationScan() {
applicationContext.getBeanDefinition("mapperScanner").getPropertyValues().add(
"annotationClass", Component.class);
"annotationClass", Mapper.class);

startContext();

Expand All @@ -145,7 +145,7 @@ public void testMarkerInterfaceAndAnnotationScan() {
applicationContext.getBeanDefinition("mapperScanner").getPropertyValues().add(
"markerInterface", MapperInterface.class);
applicationContext.getBeanDefinition("mapperScanner").getPropertyValues().add(
"annotationClass", Component.class);
"annotationClass", Mapper.class);

startContext();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2010-2016 the original author or authors.
* Copyright 2010-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,12 +15,12 @@
*/
package org.mybatis.spring.mapper.child;

import org.mybatis.spring.annotation.Mapper;
import org.mybatis.spring.mapper.MapperInterface;
import org.springframework.stereotype.Component;

// interface for MapperScannerPostProcessor tests
// tests subpackage search
@Component
@Mapper
public interface MapperChildInterface extends MapperInterface {
public void childMethod();
}