|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: REQUIRED | OPTIONAL | DETAIL: ELEMENT |
@Retention(value=RUNTIME) @Target(value=TYPE) @Documented @Import(value=MapperScannerRegistrar.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
.
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(); } }
MapperScannerRegistrar
,
MapperFactoryBean
Optional Element Summary | |
---|---|
Class<? extends Annotation> |
annotationClass
This property specifies the annotation that the scanner will search for. |
Class<?>[] |
basePackageClasses
Type-safe alternative to basePackages() for specifying the packages
to scan for annotated components. |
String[] |
basePackages
Base packages to scan for MyBatis interfaces. |
Class<?> |
markerInterface
This property specifies the parent that the scanner will search for. |
Class<? extends org.springframework.beans.factory.support.BeanNameGenerator> |
nameGenerator
The BeanNameGenerator class to be used for naming detected components
within the Spring container. |
String |
sqlSessionFactoryRef
Specifies which SqlSessionFactory to use in the case that there is
more than one in the spring context. |
String |
sqlSessionTemplateRef
Specifies which SqlSessionTemplate to use in the case that there is
more than one in the spring context. |
String[] |
value
Alias for the basePackages() attribute. |
public abstract String[] value
basePackages()
attribute. Allows for more concise
annotation declarations e.g.:
@EnableMyBatisMapperScanner("org.my.pkg")
instead of {@code
public abstract String[] basePackages
public abstract Class<?>[] basePackageClasses
basePackages()
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.
public abstract Class<? extends org.springframework.beans.factory.support.BeanNameGenerator> nameGenerator
BeanNameGenerator
class to be used for naming detected components
within the Spring container.
public abstract Class<? extends Annotation> annotationClass
The scanner will register all interfaces in the base package that also have the specified annotation.
Note this can be combined with markerInterface.
public abstract Class<?> markerInterface
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.
public abstract String sqlSessionTemplateRef
SqlSessionTemplate
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.
public abstract String sqlSessionFactoryRef
SqlSessionFactory
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.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: REQUIRED | OPTIONAL | DETAIL: ELEMENT |