Skip to content

Commit 8623026

Browse files
committed
added more tests and fixed javadoc
1 parent aa5de2f commit 8623026

File tree

4 files changed

+54
-3
lines changed

4 files changed

+54
-3
lines changed

src/main/java/org/mybatis/spring/annotation/MapperScan.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@
3333
* {@link MapperScannerConfigurer} via {@link MapperScannerRegistrar}.
3434
*
3535
* <p>Either {@link #basePackageClasses} or {@link #basePackages} (or its alias
36-
* {@link #value}) may be specified to define specific packages to scan. If specific
37-
* packages are not defined, scanning will occur from the package of the
38-
* class that declares this annotation.
36+
* {@link #value}) may be specified to define specific packages to scan.
37+
* Since 2.0.4, If specific packages are not defined, scanning will occur from
38+
* the package of the class that declares this annotation.
3939
*
4040
* <p>
4141
* Configuration example:

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
import org.junit.jupiter.api.Test;
2727
import org.mybatis.spring.SqlSessionFactoryBean;
2828
import org.mybatis.spring.SqlSessionTemplate;
29+
import org.mybatis.spring.annotation.mapper.ds1.AppConfigWithDefaultMapperScanAndRepeat;
30+
import org.mybatis.spring.annotation.mapper.ds1.AppConfigWithDefaultMapperScans;
2931
import org.mybatis.spring.annotation.mapper.ds1.Ds1Mapper;
3032
import org.mybatis.spring.mapper.AnnotatedMapper;
3133
import org.mybatis.spring.mapper.AppConfigWithDefaultPackageScan;
@@ -289,6 +291,32 @@ void testScanWithMapperScans() {
289291
applicationContext.getBean("ds2Mapper");
290292
}
291293

294+
@Test
295+
void testScanWithDefaultMapperScanAndRepeat() {
296+
applicationContext.register(AppConfigWithDefaultMapperScanAndRepeat.class);
297+
298+
startContext();
299+
300+
SqlSessionFactory sqlSessionFactory = applicationContext.getBean(SqlSessionFactory.class);
301+
assertEquals(2, sqlSessionFactory.getConfiguration().getMapperRegistry().getMappers().size());
302+
303+
applicationContext.getBean("ds1Mapper");
304+
applicationContext.getBean("ds2Mapper");
305+
}
306+
307+
@Test
308+
void testScanWithDefaultMapperScans() {
309+
applicationContext.register(AppConfigWithDefaultMapperScans.class);
310+
311+
startContext();
312+
313+
SqlSessionFactory sqlSessionFactory = applicationContext.getBean(SqlSessionFactory.class);
314+
assertEquals(2, sqlSessionFactory.getConfiguration().getMapperRegistry().getMappers().size());
315+
316+
applicationContext.getBean("ds1Mapper");
317+
applicationContext.getBean("ds2Mapper");
318+
}
319+
292320
@Test
293321
void testLazyScanWithPropertySourcesPlaceholderConfigurer() {
294322
applicationContext.register(LazyConfigWithPropertySourcesPlaceholderConfigurer.class);
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package org.mybatis.spring.annotation.mapper.ds1;
2+
3+
import org.mybatis.spring.annotation.MapperScan;
4+
import org.springframework.context.annotation.Configuration;
5+
6+
@Configuration
7+
@MapperScan
8+
@MapperScan("org.mybatis.spring.annotation.mapper.ds2")
9+
public class AppConfigWithDefaultMapperScanAndRepeat {
10+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package org.mybatis.spring.annotation.mapper.ds1;
2+
3+
import org.mybatis.spring.annotation.MapperScan;
4+
import org.mybatis.spring.annotation.MapperScans;
5+
import org.springframework.context.annotation.Configuration;
6+
7+
@Configuration
8+
@MapperScans({
9+
@MapperScan,
10+
@MapperScan("org.mybatis.spring.annotation.mapper.ds2")
11+
})
12+
public class AppConfigWithDefaultMapperScans {
13+
}

0 commit comments

Comments
 (0)