org.mybatis.spring.mapper
Class MapperScannerConfigurer

java.lang.Object
  extended by org.mybatis.spring.mapper.MapperScannerConfigurer
All Implemented Interfaces:
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

BeanDefinitionRegistryPostProcessor that searches recursively starting from a base package for interfaces and registers them as MapperFactoryBean. Note that only interfaces with at least one method will be registered; concrete classes will be ignored.

The basePackage property 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 annotationClass property specifies an annotation to search for. The markerInterface property 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 given basePackage are added as mappers.

This configurer is usually used with autowire enabled so all the beans it creates are automatically autowired with the proper SqlSessionFactory or SqlSessionTemplate. If there is more than one SqlSessionFactory in the application, however, autowiring cannot be used. In this case you must explicitly specify either an SqlSessionFactory or an SqlSessionTemplate to use.

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="sqlSessionFactory" value="sqlSessionFactory" />
   </bean>
 
 

Version:
$Id: MapperScannerConfigurer.java 3888 2011-09-05 13:52:48Z putthibongb $
See Also:
MapperFactoryBean

Constructor Summary
MapperScannerConfigurer()
           
 
Method Summary
 void afterPropertiesSet()
          
 void postProcessBeanDefinitionRegistry(org.springframework.beans.factory.support.BeanDefinitionRegistry beanDefinitionRegistry)
          
 void postProcessBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory)
          
 void setAddToConfig(boolean addToConfig)
           
 void setAnnotationClass(Class<? extends Annotation> annotationClass)
           
 void setApplicationContext(org.springframework.context.ApplicationContext applicationContext)
          
 void setBasePackage(String basePackage)
           
 void setMarkerInterface(Class<?> superClass)
           
 void setSqlSessionFactory(org.apache.ibatis.session.SqlSessionFactory sqlSessionFactory)
           
 void setSqlSessionTemplate(SqlSessionTemplate sqlSessionTemplate)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MapperScannerConfigurer

public MapperScannerConfigurer()
Method Detail

setBasePackage

public void setBasePackage(String basePackage)

setAddToConfig

public void setAddToConfig(boolean addToConfig)

setAnnotationClass

public void setAnnotationClass(Class<? extends Annotation> annotationClass)

setMarkerInterface

public void setMarkerInterface(Class<?> superClass)

setSqlSessionFactory

public void setSqlSessionFactory(org.apache.ibatis.session.SqlSessionFactory sqlSessionFactory)

setSqlSessionTemplate

public void setSqlSessionTemplate(SqlSessionTemplate sqlSessionTemplate)

setApplicationContext

public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext)

Specified by:
setApplicationContext in interface org.springframework.context.ApplicationContextAware

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)

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

postProcessBeanDefinitionRegistry

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

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


Copyright © 2010-2011 MyBatis.org. All Rights Reserved.