注释类型 MapperScan
-
@Retention(RUNTIME) @Target(TYPE) @Documented @Import(MapperScannerRegistrar.class) public @interface MapperScan
Use this annotation to register MyBatis mapper interfaces when using Java Config. It performs when same work asMapperScannerConfigurerviaMapperScannerRegistrar.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(); } }- 从以下版本开始:
- 1.2.0
- 作者:
- Michael Lanyon, Eduardo Macarron
- 另请参阅:
MapperScannerRegistrar,MapperFactoryBean
-
-
可选元素概要
可选元素 修饰符和类型 可选元素 说明 Class<? extends Annotation>annotationClassThis property specifies the annotation that the scanner will search for.Class<?>[]basePackageClassesType-safe alternative tobasePackages()for specifying the packages to scan for annotated components.String[]basePackagesBase packages to scan for MyBatis interfaces.Class<? extends MapperFactoryBean>factoryBeanSpecifies a custom MapperFactoryBean to return a mybatis proxy as spring bean.StringmapperHelperRef还可以直接配置一个 MapperHelper beanClass<?>markerInterfaceThis property specifies the parent that the scanner will search for.Class<? extends org.springframework.beans.factory.support.BeanNameGenerator>nameGeneratorTheBeanNameGeneratorclass to be used for naming detected components within the Spring container.String[]properties通用 Mapper 的配置,一行一个配置StringsqlSessionFactoryRefSpecifies whichSqlSessionFactoryto use in the case that there is more than one in the spring context.StringsqlSessionTemplateRefSpecifies whichSqlSessionTemplateto use in the case that there is more than one in the spring context.String[]valueAlias for thebasePackages()attribute.
-
-
-
元素详细资料
-
value
String[] value
Alias for thebasePackages()attribute. Allows for more concise annotation declarations e.g.:@EnableMyBatisMapperScanner("org.my.pkg")instead of {@code- 默认值:
- {}
-
-
-
basePackages
String[] 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.- 默认值:
- {}
-
-
-
basePackageClasses
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.
- 默认值:
- {}
-
-
-
nameGenerator
Class<? extends org.springframework.beans.factory.support.BeanNameGenerator> nameGenerator
TheBeanNameGeneratorclass to be used for naming detected components within the Spring container.- 默认值:
- org.springframework.beans.factory.support.BeanNameGenerator.class
-
-
-
annotationClass
Class<? extends 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.
- 默认值:
- java.lang.annotation.Annotation.class
-
-
-
markerInterface
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.
- 默认值:
- java.lang.Class.class
-
-
-
sqlSessionTemplateRef
String sqlSessionTemplateRef
Specifies whichSqlSessionTemplateto 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.- 默认值:
- ""
-
-
-
sqlSessionFactoryRef
String sqlSessionFactoryRef
Specifies whichSqlSessionFactoryto 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.- 默认值:
- ""
-
-
-
factoryBean
Class<? extends MapperFactoryBean> factoryBean
Specifies a custom MapperFactoryBean to return a mybatis proxy as spring bean.- 默认值:
- tk.mybatis.spring.mapper.MapperFactoryBean.class
-
-
-
properties
String[] properties
通用 Mapper 的配置,一行一个配置- 返回:
- 默认值:
- {}
-
-
-
mapperHelperRef
String mapperHelperRef
还可以直接配置一个 MapperHelper bean- 返回:
- 默认值:
- ""
-
-