Skip to content

Commit b626058

Browse files
committed
Add @Mapper annotation
1 parent 4b63249 commit b626058

File tree

8 files changed

+57
-21
lines changed

8 files changed

+57
-21
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* Copyright 2010-2017 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.mybatis.spring.annotation;
17+
18+
import java.lang.annotation.Inherited;
19+
import java.lang.annotation.Retention;
20+
import java.lang.annotation.Target;
21+
22+
import java.lang.annotation.Documented;
23+
import static java.lang.annotation.ElementType.TYPE;
24+
import static java.lang.annotation.RetentionPolicy.RUNTIME;
25+
26+
/**
27+
* Marker interface for indicate the MyBatis mapper.
28+
*
29+
* @author Kazuki Shimizu
30+
* @since 1.3.2
31+
*/
32+
@Documented
33+
@Inherited
34+
@Retention(RUNTIME)
35+
@Target(TYPE)
36+
public @interface Mapper {
37+
}

src/test/java/org/mybatis/spring/annotation/MapperScanTest.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2010-2016 the original author or authors.
2+
* Copyright 2010-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -37,7 +37,6 @@
3737
import org.springframework.beans.factory.support.GenericBeanDefinition;
3838
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
3939
import org.springframework.context.annotation.Configuration;
40-
import org.springframework.stereotype.Component;
4140

4241
import com.mockrunner.mock.jdbc.MockDataSource;
4342

@@ -257,12 +256,12 @@ public static class AppConfigWithMarkerInterface {
257256
}
258257

259258
@Configuration
260-
@MapperScan(basePackages = "org.mybatis.spring.mapper", annotationClass = Component.class)
259+
@MapperScan(basePackages = "org.mybatis.spring.mapper", annotationClass = Mapper.class)
261260
public static class AppConfigWithAnnotation {
262261
}
263262

264263
@Configuration
265-
@MapperScan(basePackages = "org.mybatis.spring.mapper", annotationClass = Component.class, markerInterface = MapperInterface.class)
264+
@MapperScan(basePackages = "org.mybatis.spring.mapper", annotationClass = Mapper.class, markerInterface = MapperInterface.class)
266265
public static class AppConfigWithMarkerInterfaceAndAnnotation {
267266
}
268267

src/test/java/org/mybatis/spring/config/annotation.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!--
33
4-
Copyright 2010-2016 the original author or authors.
4+
Copyright 2010-2017 the original author or authors.
55
66
Licensed under the Apache License, Version 2.0 (the "License");
77
you may not use this file except in compliance with the License.
@@ -32,5 +32,5 @@
3232
<!-- Scan for mappers and let them be autowired; notice there is no
3333
UserDaoImplementation needed. The required SqlSessionFactory will be
3434
autowired. -->
35-
<mybatis:scan base-package="org.mybatis.spring.mapper" annotation="org.springframework.stereotype.Component"/>
35+
<mybatis:scan base-package="org.mybatis.spring.mapper" annotation="org.mybatis.spring.annotation.Mapper"/>
3636
</beans>

src/test/java/org/mybatis/spring/config/marker-and-annotation.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!--
33
4-
Copyright 2010-2016 the original author or authors.
4+
Copyright 2010-2017 the original author or authors.
55
66
Licensed under the Apache License, Version 2.0 (the "License");
77
you may not use this file except in compliance with the License.
@@ -34,5 +34,5 @@
3434
autowired. -->
3535
<mybatis:scan base-package="org.mybatis.spring.mapper"
3636
marker-interface="org.mybatis.spring.mapper.MapperInterface"
37-
annotation="org.springframework.stereotype.Component" />
37+
annotation="org.mybatis.spring.annotation.Mapper" />
3838
</beans>

src/test/java/org/mybatis/spring/mapper/AnnotatedMapper.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2010-2016 the original author or authors.
2+
* Copyright 2010-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -15,11 +15,11 @@
1515
*/
1616
package org.mybatis.spring.mapper;
1717

18-
import org.springframework.stereotype.Component;
18+
import org.mybatis.spring.annotation.Mapper;
1919

2020
// annotated interface for MapperScannerPostProcessor tests
2121
// ensures annotated classes are loaded
22-
@Component
22+
@Mapper
2323
public interface AnnotatedMapper {
2424
public void method();
2525
}

src/test/java/org/mybatis/spring/mapper/AnnotatedMapperZeroMethods.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2010-2016 the original author or authors.
2+
* Copyright 2010-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -15,10 +15,10 @@
1515
*/
1616
package org.mybatis.spring.mapper;
1717

18-
import org.springframework.stereotype.Component;
18+
import org.mybatis.spring.annotation.Mapper;
1919

2020
// annotated interface for MapperScannerPostProcessor tests
2121
// ensures annotated class with no methods is not loaded
22-
@Component
22+
@Mapper
2323
public interface AnnotatedMapperZeroMethods {
2424
}

src/test/java/org/mybatis/spring/mapper/MapperScannerConfigurerTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2010-2016 the original author or authors.
2+
* Copyright 2010-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -27,6 +27,7 @@
2727
import org.junit.Test;
2828
import org.mybatis.spring.SqlSessionFactoryBean;
2929
import org.mybatis.spring.SqlSessionTemplate;
30+
import org.mybatis.spring.annotation.Mapper;
3031
import org.mybatis.spring.mapper.child.MapperChildInterface;
3132
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
3233
import org.springframework.beans.factory.config.BeanDefinition;
@@ -36,7 +37,6 @@
3637
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
3738
import org.springframework.beans.factory.support.GenericBeanDefinition;
3839
import org.springframework.context.support.GenericApplicationContext;
39-
import org.springframework.stereotype.Component;
4040

4141
import com.mockrunner.mock.jdbc.MockDataSource;
4242

@@ -128,7 +128,7 @@ public void testMarkerInterfaceScan() {
128128
@Test
129129
public void testAnnotationScan() {
130130
applicationContext.getBeanDefinition("mapperScanner").getPropertyValues().add(
131-
"annotationClass", Component.class);
131+
"annotationClass", Mapper.class);
132132

133133
startContext();
134134

@@ -145,7 +145,7 @@ public void testMarkerInterfaceAndAnnotationScan() {
145145
applicationContext.getBeanDefinition("mapperScanner").getPropertyValues().add(
146146
"markerInterface", MapperInterface.class);
147147
applicationContext.getBeanDefinition("mapperScanner").getPropertyValues().add(
148-
"annotationClass", Component.class);
148+
"annotationClass", Mapper.class);
149149

150150
startContext();
151151

src/test/java/org/mybatis/spring/mapper/child/MapperChildInterface.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2010-2016 the original author or authors.
2+
* Copyright 2010-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -15,12 +15,12 @@
1515
*/
1616
package org.mybatis.spring.mapper.child;
1717

18+
import org.mybatis.spring.annotation.Mapper;
1819
import org.mybatis.spring.mapper.MapperInterface;
19-
import org.springframework.stereotype.Component;
2020

2121
// interface for MapperScannerPostProcessor tests
2222
// tests subpackage search
23-
@Component
23+
@Mapper
2424
public interface MapperChildInterface extends MapperInterface {
2525
public void childMethod();
2626
}

0 commit comments

Comments
 (0)