Annotation Interface MapperScan


@Retention(RUNTIME) @Target(TYPE) @Documented @Import(MapperScannerRegistrar.class) @Repeatable(MapperScans.class) public @interface MapperScan
Use this annotation to register MyBatis mapper interfaces when using Java Config. It performs when same work as MapperScannerConfigurer via MapperScannerRegistrar.

Either basePackageClasses() or basePackages() (or its alias value()) may be specified to define specific packages to scan. Since 2.0.4, If specific packages are not defined, scanning will occur from the package of the class that declares this annotation.

Configuration example:

 @Configuration
 @MapperScan("org.mybatis.spring.sample.mapper")
 public class AppConfig {

   @Bean
   public DataSource dataSource() {
     return new EmbeddedDatabaseBuilder().addScript("schema.sql").build();
   }

   @Bean
   public DataSourceTransactionManager transactionManager() {
     return new DataSourceTransactionManager(dataSource());
   }

   @Bean
   public SqlSessionFactory sqlSessionFactory() throws Exception {
     SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
     sessionFactory.setDataSource(dataSource());
     return sessionFactory.getObject();
   }
 }
 
Since:
1.2.0
Author:
Michael Lanyon, Eduardo Macarron, Qimiao Chen
See Also: