org.mybatis.spring.annotation
Class MapperScannerPostProcessor

java.lang.Object
  extended by org.mybatis.spring.annotation.MapperScannerPostProcessor
All Implemented Interfaces:
org.springframework.beans.factory.config.BeanFactoryPostProcessor, org.springframework.beans.factory.InitializingBean, org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor

public class MapperScannerPostProcessor
extends Object
implements org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor, org.springframework.beans.factory.InitializingBean

BeanDefinitionRegistryPostProcessor that searches recursively starting from a basePackage for interfaces with Mapper annotation and registers MapperFactoryBeans.

It is usually used with autowire enabled so all the beans it creates are automatically autowired with the proper SqlSessionFactory or SqlSessionTemplate

It there is more than one DataSource or SqlSessionFactory in the application autowire cannot be used. In this case you can specify SqlSessionFactory or SqlSessionTemplate to use.

When specifying any of these beans notice that bean names must be used instead of real references. It has to be this way because the MapperScannerPostProcessor runs very early in the Spring startup process and some other post processors have not started yet (like PropertyPlaceholderConfigurer) and if they are needed (for example to setup the DataSource) the start process will fail.

Configuration sample:

 <bean class="org.mybatis.spring.annotation.MapperScannerPostProcessor">
       <property name="basePackage" value="org.mybatis.spring.sample.mapper" />
       <!-- optional, notice that "value" is used, not "ref" -->
       <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
   </bean>
 
 

Version:
$Id: MapperScannerPostProcessor.java 2965 2010-10-30 14:43:51Z simone.tripodi $
See Also:
SqlSessionFactory, MapperFactoryBean

Constructor Summary
MapperScannerPostProcessor()
           
 
Method Summary
 void afterPropertiesSet()
          
 void postProcessBeanDefinitionRegistry(org.springframework.beans.factory.support.BeanDefinitionRegistry registry)
          
 void postProcessBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory)
          
 void setAddToConfig(boolean addToConfig)
           
 void setBasePackage(String basePackage)
           
 void setSqlSessionFactoryBeanName(String sqlSessionFactoryName)
           
 void setSqlSessionTemplateBeanName(String sqlSessionTemplateName)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MapperScannerPostProcessor

public MapperScannerPostProcessor()
Method Detail

setBasePackage

public void setBasePackage(String basePackage)

setAddToConfig

public void setAddToConfig(boolean addToConfig)

setSqlSessionTemplateBeanName

public void setSqlSessionTemplateBeanName(String sqlSessionTemplateName)

setSqlSessionFactoryBeanName

public void setSqlSessionFactoryBeanName(String sqlSessionFactoryName)

afterPropertiesSet

public void afterPropertiesSet()
                        throws Exception

Specified by:
afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
Throws:
Exception

postProcessBeanFactory

public void postProcessBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory)
                            throws org.springframework.beans.BeansException

Specified by:
postProcessBeanFactory in interface org.springframework.beans.factory.config.BeanFactoryPostProcessor
Throws:
org.springframework.beans.BeansException

postProcessBeanDefinitionRegistry

public void postProcessBeanDefinitionRegistry(org.springframework.beans.factory.support.BeanDefinitionRegistry registry)
                                       throws org.springframework.beans.BeansException

Specified by:
postProcessBeanDefinitionRegistry in interface org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor
Throws:
org.springframework.beans.BeansException


Copyright © 2010 MyBatis.org. All Rights Reserved.