Class MapperFactoryBean<T>
java.lang.Object
org.springframework.dao.support.DaoSupport
org.mybatis.spring.support.SqlSessionDaoSupport
org.mybatis.spring.mapper.MapperFactoryBean<T>
- Type Parameters:
T- the generic type
- 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:
-
Field Summary
Fields inherited from class org.springframework.dao.support.DaoSupport
loggerFields inherited from interface org.springframework.beans.factory.FactoryBean
OBJECT_TYPE_ATTRIBUTE -
Constructor Summary
ConstructorsConstructorDescriptionInstantiates a new mapper factory bean.MapperFactoryBean(Class<T> mapperInterface) Instantiates a new mapper factory bean. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidReturn the mapper interface of the MyBatis mapperbooleanReturn the flag for addition into MyBatis config.booleanvoidsetAddToConfig(boolean addToConfig) If addToConfig is false the mapper will not be added to MyBatis.voidsetMapperInterface(Class<T> mapperInterface) Sets the mapper interface of the MyBatis mapperMethods inherited from class SqlSessionDaoSupport
createSqlSessionTemplate, getSqlSession, getSqlSessionFactory, getSqlSessionTemplate, setSqlSessionFactory, setSqlSessionTemplateMethods inherited from class org.springframework.dao.support.DaoSupport
afterPropertiesSet, initDao
-
Constructor Details
-
MapperFactoryBean
public MapperFactoryBean()Instantiates a new mapper factory bean. -
MapperFactoryBean
-
-
Method Details
-
checkDaoConfig
protected void checkDaoConfig()- Overrides:
checkDaoConfigin classSqlSessionDaoSupport
-
getObject
-
getObjectType
-
isSingleton
public boolean isSingleton()- Specified by:
isSingletonin interfaceorg.springframework.beans.factory.FactoryBean<T>
-
setMapperInterface
-
getMapperInterface
-
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.
-