Package org.mybatis.spring.mapper
Class MapperFactoryBean<T>
- java.lang.Object
-
- org.springframework.dao.support.DaoSupport
-
- org.mybatis.spring.support.SqlSessionDaoSupport
-
- org.mybatis.spring.mapper.MapperFactoryBean<T>
-
- All Implemented Interfaces:
org.springframework.beans.factory.FactoryBean<T>
,org.springframework.beans.factory.InitializingBean
public class MapperFactoryBean<T> extends SqlSessionDaoSupport implements org.springframework.beans.factory.FactoryBean<T>
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.
- Author:
- Eduardo Macarron
- See Also:
SqlSessionTemplate
-
-
Constructor Summary
Constructors Constructor Description MapperFactoryBean()
MapperFactoryBean(java.lang.Class<T> mapperInterface)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
checkDaoConfig()
java.lang.Class<T>
getMapperInterface()
Return the mapper interface of the MyBatis mapperT
getObject()
java.lang.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(java.lang.Class<T> mapperInterface)
Sets the mapper interface of the MyBatis mapper-
Methods inherited from class org.mybatis.spring.support.SqlSessionDaoSupport
createSqlSessionTemplate, getSqlSession, getSqlSessionFactory, getSqlSessionTemplate, setSqlSessionFactory, setSqlSessionTemplate
-
-
-
-
Constructor Detail
-
MapperFactoryBean
public MapperFactoryBean()
-
MapperFactoryBean
public MapperFactoryBean(java.lang.Class<T> mapperInterface)
-
-
Method Detail
-
checkDaoConfig
protected void checkDaoConfig()
- Overrides:
checkDaoConfig
in classSqlSessionDaoSupport
-
getObject
public T getObject() throws java.lang.Exception
- Specified by:
getObject
in interfaceorg.springframework.beans.factory.FactoryBean<T>
- Throws:
java.lang.Exception
-
getObjectType
public java.lang.Class<T> getObjectType()
- Specified by:
getObjectType
in interfaceorg.springframework.beans.factory.FactoryBean<T>
-
isSingleton
public boolean isSingleton()
- Specified by:
isSingleton
in interfaceorg.springframework.beans.factory.FactoryBean<T>
-
setMapperInterface
public void setMapperInterface(java.lang.Class<T> mapperInterface)
Sets the mapper interface of the MyBatis mapper- Parameters:
mapperInterface
- class of the interface
-
getMapperInterface
public java.lang.Class<T> getMapperInterface()
Return the mapper interface of the MyBatis mapper- Returns:
- class of the interface
-
setAddToConfig
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 addToConfig is true.
- Parameters:
addToConfig
- a flag that whether add mapper to MyBatis or not
-
isAddToConfig
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.
-
-