public class

MapperFactoryBean

extends SqlSessionDaoSupport
implements FactoryBean<T>
java.lang.Object
   ↳ org.springframework.dao.support.DaoSupport
     ↳ org.mybatis.spring.support.SqlSessionDaoSupport
       ↳ org.mybatis.spring.mapper.MapperFactoryBean<T>

Class Overview

BeanFactory that enables injection of MyBatis mapper interfaces. It can be set up with a SqlSessionFactory or a pre-configured SqlSessionTemplate.

Sample configuration:

 <bean id="baseMapper" class="org.mybatis.spring.mapper.MapperFactoryBean" abstract="true" lazy-init="true">
     <property name="sqlSessionFactory" ref="sqlSessionFactory" />
   </bean>

   <bean id="oneMapper" parent="baseMapper">
     <property name="mapperInterface" value="my.package.MyMapperInterface" />
   </bean>

   <bean id="anotherMapper" parent="baseMapper">
     <property name="mapperInterface" value="my.package.MyAnotherMapperInterface" />
   </bean>
 
 

Note that this factory can only inject interfaces, not concrete classes.

Summary

[Expand]
Inherited Fields
From class org.springframework.dao.support.DaoSupport
Public Constructors
MapperFactoryBean()
MapperFactoryBean(Class<T> mapperInterface)
Public Methods
Class<T> getMapperInterface()
Return the mapper interface of the MyBatis mapper
T getObject()
Class<T> getObjectType()
boolean isAddToConfig()
Return the flag for addition into MyBatis config.
boolean isSingleton()
void setAddToConfig(boolean addToConfig)
If addToConfig is false the mapper will not be added to MyBatis.
void setMapperInterface(Class<T> mapperInterface)
Sets the mapper interface of the MyBatis mapper
Protected Methods
void checkDaoConfig()
[Expand]
Inherited Methods
From class org.mybatis.spring.support.SqlSessionDaoSupport
From class org.springframework.dao.support.DaoSupport
From class java.lang.Object
From interface org.springframework.beans.factory.FactoryBean
From interface org.springframework.beans.factory.InitializingBean

Public Constructors

public MapperFactoryBean ()

public MapperFactoryBean (Class<T> mapperInterface)

Public Methods

public Class<T> getMapperInterface ()

Return the mapper interface of the MyBatis mapper

Returns
  • class of the interface

public T getObject ()

Throws
Exception

public Class<T> getObjectType ()

public boolean isAddToConfig ()

Return the flag for addition into MyBatis config.

Returns
  • true if the mapper will be added to MyBatis in the case it is not already registered.

public boolean isSingleton ()

public void setAddToConfig (boolean addToConfig)

If addToConfig is false the mapper will not be added to MyBatis. This means it must have been included in mybatis-config.xml.

If it is true, the mapper will be added to MyBatis in the case it is not already registered.

By default addToCofig is true.

public void setMapperInterface (Class<T> mapperInterface)

Sets the mapper interface of the MyBatis mapper

Parameters
mapperInterface class of the interface

Protected Methods

protected void checkDaoConfig ()