Package org.mybatis.spring.annotation
Annotation Type 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 asMapperScannerConfigurer
viaMapperScannerRegistrar
.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
- See Also:
MapperScannerRegistrar
,MapperFactoryBean
-
-
Optional Element Summary
Optional Elements Modifier and Type Optional Element Description java.lang.Class<? extends java.lang.annotation.Annotation>
annotationClass
This property specifies the annotation that the scanner will search for.java.lang.Class<?>[]
basePackageClasses
Type-safe alternative tobasePackages()
for specifying the packages to scan for annotated components.java.lang.String[]
basePackages
Base packages to scan for MyBatis interfaces.java.lang.Class<? extends MapperFactoryBean>
factoryBean
Specifies a custom MapperFactoryBean to return a mybatis proxy as spring bean.java.lang.String
lazyInitialization
Whether enable lazy initialization of mapper bean.java.lang.Class<?>
markerInterface
This property specifies the parent that the scanner will search for.java.lang.Class<? extends org.springframework.beans.factory.support.BeanNameGenerator>
nameGenerator
TheBeanNameGenerator
class to be used for naming detected components within the Spring container.java.lang.String
sqlSessionFactoryRef
Specifies whichSqlSessionFactory
to use in the case that there is more than one in the spring context.java.lang.String
sqlSessionTemplateRef
Specifies whichSqlSessionTemplate
to use in the case that there is more than one in the spring context.java.lang.String[]
value
Alias for thebasePackages()
attribute.
-
-
-
Element Detail
-
value
java.lang.String[] value
Alias for thebasePackages()
attribute. Allows for more concise annotation declarations e.g.:@MapperScan("org.my.pkg")
instead of@MapperScan(basePackages = "org.my.pkg"
)}.- Returns:
- base package names
- Default:
- {}
-
-
-
basePackageClasses
java.lang.Class<?>[] basePackageClasses
Type-safe alternative tobasePackages()
for specifying the packages to scan for annotated components. The package of each class specified will be scanned.Consider creating a special no-op marker class or interface in each package that serves no purpose other than being referenced by this attribute.
- Returns:
- classes that indicate base package for scanning mapper interface
- Default:
- {}
-
-
-
nameGenerator
java.lang.Class<? extends org.springframework.beans.factory.support.BeanNameGenerator> nameGenerator
TheBeanNameGenerator
class to be used for naming detected components within the Spring container.- Returns:
- the class of
BeanNameGenerator
- Default:
- org.springframework.beans.factory.support.BeanNameGenerator.class
-
-
-
annotationClass
java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass
This property specifies the annotation that the scanner will search for.The scanner will register all interfaces in the base package that also have the specified annotation.
Note this can be combined with markerInterface.
- Returns:
- the annotation that the scanner will search for
- Default:
- java.lang.annotation.Annotation.class
-
-
-
markerInterface
java.lang.Class<?> markerInterface
This property specifies the parent that the scanner will search for.The scanner will register all interfaces in the base package that also have the specified interface class as a parent.
Note this can be combined with annotationClass.
- Returns:
- the parent that the scanner will search for
- Default:
- java.lang.Class.class
-
-
-
factoryBean
java.lang.Class<? extends MapperFactoryBean> factoryBean
Specifies a custom MapperFactoryBean to return a mybatis proxy as spring bean.- Returns:
- the class of
MapperFactoryBean
- Default:
- org.mybatis.spring.mapper.MapperFactoryBean.class
-
-