类 MapperScannerConfigurer
- java.lang.Object
-
- tk.mybatis.spring.mapper.MapperScannerConfigurer
-
- 所有已实现的接口:
org.springframework.beans.factory.Aware,org.springframework.beans.factory.BeanNameAware,org.springframework.beans.factory.config.BeanFactoryPostProcessor,org.springframework.beans.factory.InitializingBean,org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor,org.springframework.context.ApplicationContextAware
public class MapperScannerConfigurer extends Object implements org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor, org.springframework.beans.factory.InitializingBean, org.springframework.context.ApplicationContextAware, org.springframework.beans.factory.BeanNameAware
BeanDefinitionRegistryPostProcessor that searches recursively starting from a base package for interfaces and registers them asMapperFactoryBean. Note that only interfaces with at least one method will be registered; concrete classes will be ignored.This class was a {code BeanFactoryPostProcessor} until 1.0.1 version. It changed to
BeanDefinitionRegistryPostProcessorin 1.0.2. See https://jira.springsource.org/browse/SPR-8269 for the details.The
basePackageproperty can contain more than one package name, separated by either commas or semicolons.This class supports filtering the mappers created by either specifying a marker interface or an annotation. The
annotationClassproperty specifies an annotation to search for. ThemarkerInterfaceproperty specifies a parent interface to search for. If both properties are specified, mappers are added for interfaces that match either criteria. By default, these two properties are null, so all interfaces in the givenbasePackageare added as mappers.This configurer enables autowire for all the beans that it creates so that they are automatically autowired with the proper
SqlSessionFactoryorSqlSessionTemplate. If there is more than oneSqlSessionFactoryin the application, however, autowiring cannot be used. In this case you must explicitly specify either anSqlSessionFactoryor anSqlSessionTemplateto use via the bean name properties. Bean names are used rather than actual objects because Spring does not initialize property placeholders until after this class is processed.Passing in an actual object which may require placeholders (i.e. DB user password) will fail. Using bean names defers actual object creation until later in the startup process, after all placeholder substituation is completed. However, note that this configurer does support property placeholders of its own properties. The
basePackageand bean name properties all support${property}style substitution.Configuration sample:
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="org.mybatis.spring.sample.mapper" /> <!-- optional unless there are multiple session factories defined --> <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" /> </bean>- 作者:
- Hunter Presnall, Eduardo Macarron, liuzh
- 另请参阅:
MapperFactoryBean,ClassPathMapperScanner
-
-
构造器概要
构造器 构造器 说明 MapperScannerConfigurer()
-
方法概要
所有方法 实例方法 具体方法 已过时的方法 修饰符和类型 方法 说明 voidafterPropertiesSet()tk.mybatis.mapper.mapperhelper.MapperHelpergetMapperHelper()org.springframework.beans.factory.support.BeanNameGeneratorgetNameGenerator()Gets beanNameGenerator to be used while running the scanner.voidpostProcessBeanDefinitionRegistry(org.springframework.beans.factory.support.BeanDefinitionRegistry registry)voidpostProcessBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory)voidsetAddToConfig(boolean addToConfig)Same asMapperFactoryBean#setAddToConfig(boolean).voidsetAnnotationClass(Class<? extends Annotation> annotationClass)This property specifies the annotation that the scanner will search for.voidsetApplicationContext(org.springframework.context.ApplicationContext applicationContext)voidsetBasePackage(String basePackage)This property lets you set the base package for your mapper interface files.voidsetBeanName(String name)voidsetMapperHelper(tk.mybatis.mapper.mapperhelper.MapperHelper mapperHelper)voidsetMarkerInterface(Class<?> superClass)This property specifies the parent that the scanner will search for.voidsetNameGenerator(org.springframework.beans.factory.support.BeanNameGenerator nameGenerator)Sets beanNameGenerator to be used while running the scanner.voidsetProcessPropertyPlaceHolders(boolean processPropertyPlaceHolders)voidsetProperties(Properties properties)属性注入voidsetSqlSessionFactory(org.apache.ibatis.session.SqlSessionFactory sqlSessionFactory)已过时。UsesetSqlSessionFactoryBeanName(String)instead.voidsetSqlSessionFactoryBeanName(String sqlSessionFactoryName)Specifies whichSqlSessionFactoryto use in the case that there is more than one in the spring context.voidsetSqlSessionTemplate(org.mybatis.spring.SqlSessionTemplate sqlSessionTemplate)已过时。UsesetSqlSessionTemplateBeanName(String)insteadvoidsetSqlSessionTemplateBeanName(String sqlSessionTemplateName)Specifies whichSqlSessionTemplateto use in the case that there is more than one in the spring context.
-
-
-
方法详细资料
-
getMapperHelper
public tk.mybatis.mapper.mapperhelper.MapperHelper getMapperHelper()
-
setMapperHelper
public void setMapperHelper(tk.mybatis.mapper.mapperhelper.MapperHelper mapperHelper)
-
afterPropertiesSet
public void afterPropertiesSet() throws Exception- 指定者:
afterPropertiesSet在接口中org.springframework.beans.factory.InitializingBean- 抛出:
Exception
-
postProcessBeanFactory
public void postProcessBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory)
- 指定者:
postProcessBeanFactory在接口中org.springframework.beans.factory.config.BeanFactoryPostProcessor
-
postProcessBeanDefinitionRegistry
public void postProcessBeanDefinitionRegistry(org.springframework.beans.factory.support.BeanDefinitionRegistry registry)
- 指定者:
postProcessBeanDefinitionRegistry在接口中org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor- 从以下版本开始:
- 1.0.2
-
getNameGenerator
public org.springframework.beans.factory.support.BeanNameGenerator getNameGenerator()
Gets beanNameGenerator to be used while running the scanner.- 返回:
- the beanNameGenerator BeanNameGenerator that has been configured
- 从以下版本开始:
- 1.2.0
-
setNameGenerator
public void setNameGenerator(org.springframework.beans.factory.support.BeanNameGenerator nameGenerator)
Sets beanNameGenerator to be used while running the scanner.- 参数:
nameGenerator- the beanNameGenerator to set- 从以下版本开始:
- 1.2.0
-
setAddToConfig
public void setAddToConfig(boolean addToConfig)
Same asMapperFactoryBean#setAddToConfig(boolean).- 参数:
addToConfig-- 另请参阅:
MapperFactoryBean.setAddToConfig(boolean)
-
setAnnotationClass
public void setAnnotationClass(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.
- 参数:
annotationClass- annotation class
-
setApplicationContext
public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext)
- 指定者:
setApplicationContext在接口中org.springframework.context.ApplicationContextAware
-
setBasePackage
public void setBasePackage(String basePackage)
This property lets you set the base package for your mapper interface files.You can set more than one package by using a semicolon or comma as a separator.
Mappers will be searched for recursively starting in the specified package(s).
- 参数:
basePackage- base package name
-
setBeanName
public void setBeanName(String name)
- 指定者:
setBeanName在接口中org.springframework.beans.factory.BeanNameAware
-
setMarkerInterface
public void setMarkerInterface(Class<?> superClass)
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.
- 参数:
superClass- parent class
-
setProcessPropertyPlaceHolders
public void setProcessPropertyPlaceHolders(boolean processPropertyPlaceHolders)
- 参数:
processPropertyPlaceHolders-- 从以下版本开始:
- 1.1.1
-
setSqlSessionFactory
@Deprecated public void setSqlSessionFactory(org.apache.ibatis.session.SqlSessionFactory sqlSessionFactory)
已过时。UsesetSqlSessionFactoryBeanName(String)instead.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.- 参数:
sqlSessionFactory-
-
setSqlSessionFactoryBeanName
public void setSqlSessionFactoryBeanName(String sqlSessionFactoryName)
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.Note bean names are used, not bean references. This is because the scanner loads early during the start process and it is too early to build mybatis object instances.
- 参数:
sqlSessionFactoryName- Bean name of theSqlSessionFactory- 从以下版本开始:
- 1.1.0
-
setSqlSessionTemplate
@Deprecated public void setSqlSessionTemplate(org.mybatis.spring.SqlSessionTemplate sqlSessionTemplate)
已过时。UsesetSqlSessionTemplateBeanName(String)insteadSpecifies 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.- 参数:
sqlSessionTemplate-
-
setSqlSessionTemplateBeanName
public void setSqlSessionTemplateBeanName(String sqlSessionTemplateName)
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.Note bean names are used, not bean references. This is because the scanner loads early during the start process and it is too early to build mybatis object instances.
- 参数:
sqlSessionTemplateName- Bean name of theSqlSessionTemplate- 从以下版本开始:
- 1.1.0
-
setProperties
public void setProperties(Properties properties)
属性注入- 参数:
properties-
-
-