Annotation Interface MapperScan
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:
-
Optional Element Summary
Modifier and TypeOptional ElementDescriptionClass<? extends Annotation>
This property specifies the annotation that the scanner will search for.Class<?>[]
Type-safe alternative tobasePackages()
for specifying the packages to scan for annotated components.String[]
Base packages to scan for MyBatis interfaces.Specifies the default scope of scanned mappers.Class<? extends MapperFactoryBean>
Specifies a custom MapperFactoryBean to return a mybatis proxy as spring bean.Whether enable lazy initialization of mapper bean.Class<?>
This property specifies the parent that the scanner will search for.Class<? extends org.springframework.beans.factory.support.BeanNameGenerator>
TheBeanNameGenerator
class to be used for naming detected components within the Spring container.boolean
Specifies a flag that whether execute a property placeholder processing or not.Specifies whichSqlSessionFactory
to use in the case that there is more than one in the spring context.Specifies whichSqlSessionTemplate
to use in the case that there is more than one in the spring context.String[]
Alias for thebasePackages()
attribute.
-
Element Details
-
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:
- {}
-
basePackages
Base packages to scan for MyBatis interfaces. Note that only interfaces with at least one method will be registered; concrete classes will be ignored.- Returns:
- base package names for scanning mapper interface
- Default:
- {}
-
basePackageClasses
Class<?>[] basePackageClassesType-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
Class<? extends org.springframework.beans.factory.support.BeanNameGenerator> nameGeneratorTheBeanNameGenerator
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
Class<? extends Annotation> annotationClassThis 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
Class<?> markerInterfaceThis 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
-
sqlSessionTemplateRef
String sqlSessionTemplateRefSpecifies whichSqlSessionTemplate
to use in the case that there is more than one in the spring context. Usually this is only needed when you have more than one datasource.- Returns:
- the bean name of
SqlSessionTemplate
- Default:
- ""
-
sqlSessionFactoryRef
String sqlSessionFactoryRefSpecifies whichSqlSessionFactory
to use in the case that there is more than one in the spring context. Usually this is only needed when you have more than one datasource.- Returns:
- the bean name of
SqlSessionFactory
- Default:
- ""
-
factoryBean
Class<? extends MapperFactoryBean> factoryBeanSpecifies a custom MapperFactoryBean to return a mybatis proxy as spring bean.- Returns:
- the class of
MapperFactoryBean
- Default:
- org.mybatis.spring.mapper.MapperFactoryBean.class
-
lazyInitialization
String lazyInitializationWhether enable lazy initialization of mapper bean.Default is
false
.- Returns:
- set
true
to enable lazy initialization - Since:
- 2.0.2
- Default:
- ""
-
defaultScope
String defaultScopeSpecifies the default scope of scanned mappers.Default is
""
(equiv to singleton).- Returns:
- the default scope
- Default:
- ""
-
processPropertyPlaceHolders
boolean processPropertyPlaceHoldersSpecifies a flag that whether execute a property placeholder processing or not.The default is true. This means that a property placeholder processing execute.
- Returns:
- a flag that whether execute a property placeholder processing or not
- Since:
- 3.0.3
- Default:
- true
-