public class MybatisSqlSessionFactoryBean
extends java.lang.Object
implements org.springframework.beans.factory.FactoryBean<org.apache.ibatis.session.SqlSessionFactory>, org.springframework.beans.factory.InitializingBean, org.springframework.context.ApplicationListener<org.springframework.context.ApplicationEvent>
SqlSessionFactoryBean
修改方法 buildSqlSessionFactory() 加载自定义
MybatisXmlConfigBuilder
移除 sqlSessionFactoryBuilder 属性,强制使用 `new MybatisSqlSessionFactoryBuilder()`
移除 environment 属性,强制使用 `MybatisSqlSessionFactoryBean.class.getSimpleName()`
构造器和说明 |
---|
MybatisSqlSessionFactoryBean() |
限定符和类型 | 方法和说明 |
---|---|
void |
afterPropertiesSet() |
protected org.apache.ibatis.session.SqlSessionFactory |
buildSqlSessionFactory()
Build a
SqlSessionFactory instance. |
org.apache.ibatis.cache.Cache |
getCache()
Gets the Cache.
|
com.baomidou.mybatisplus.core.MybatisConfiguration |
getConfiguration() |
org.apache.ibatis.mapping.DatabaseIdProvider |
getDatabaseIdProvider()
Gets the DatabaseIdProvider
|
org.apache.ibatis.session.SqlSessionFactory |
getObject() |
java.lang.Class<? extends org.apache.ibatis.session.SqlSessionFactory> |
getObjectType() |
java.lang.Class<? extends org.apache.ibatis.io.VFS> |
getVfs()
Gets the VFS.
|
boolean |
isSingleton() |
void |
onApplicationEvent(org.springframework.context.ApplicationEvent event) |
void |
setCache(org.apache.ibatis.cache.Cache cache)
Sets the Cache.
|
void |
setConfigLocation(org.springframework.core.io.Resource configLocation)
Set the location of the MyBatis
SqlSessionFactory config file. |
void |
setConfiguration(com.baomidou.mybatisplus.core.MybatisConfiguration configuration)
Set a customized MyBatis configuration.
|
void |
setConfigurationProperties(java.util.Properties sqlSessionFactoryProperties)
Set optional properties to be passed into the SqlSession configuration, as alternative to a
<properties> tag in the configuration xml file. |
void |
setDatabaseIdProvider(org.apache.ibatis.mapping.DatabaseIdProvider databaseIdProvider)
Sets the DatabaseIdProvider.
|
void |
setDataSource(javax.sql.DataSource dataSource)
Set the JDBC
DataSource that this instance should manage transactions for. |
void |
setDefaultScriptingLanguageDriver(java.lang.Class<? extends org.apache.ibatis.scripting.LanguageDriver> defaultScriptingLanguageDriver)
Set a default scripting language driver class.
|
void |
setFailFast(boolean failFast)
If true, a final check is done on Configuration to assure that all mapped statements are fully loaded and there is
no one still pending to resolve includes.
|
void |
setGlobalConfig(com.baomidou.mybatisplus.core.config.GlobalConfig globalConfig) |
void |
setMapperLocations(org.springframework.core.io.Resource... mapperLocations)
Set locations of MyBatis mapper files that are going to be merged into the
SqlSessionFactory configuration
at runtime. |
void |
setObjectFactory(org.apache.ibatis.reflection.factory.ObjectFactory objectFactory)
Sets the ObjectFactory.
|
void |
setObjectWrapperFactory(org.apache.ibatis.reflection.wrapper.ObjectWrapperFactory objectWrapperFactory)
Sets the ObjectWrapperFactory.
|
void |
setPlugins(org.apache.ibatis.plugin.Interceptor... plugins)
Mybatis plugin list.
|
void |
setScriptingLanguageDrivers(org.apache.ibatis.scripting.LanguageDriver... scriptingLanguageDrivers)
Set scripting language drivers.
|
void |
setTransactionFactory(org.apache.ibatis.transaction.TransactionFactory transactionFactory)
Set the MyBatis TransactionFactory to use.
|
void |
setTypeAliases(java.lang.Class<?>... typeAliases)
List of type aliases to register.
|
void |
setTypeAliasesPackage(java.lang.String typeAliasesPackage)
Packages to search for type aliases.
|
void |
setTypeAliasesSuperType(java.lang.Class<?> typeAliasesSuperType)
Super class which domain objects have to extend to have a type alias created.
|
void |
setTypeEnumsPackage(java.lang.String typeEnumsPackage)
TODO 自定义枚举包
|
void |
setTypeHandlers(org.apache.ibatis.type.TypeHandler<?>... typeHandlers)
Set type handlers.
|
void |
setTypeHandlersPackage(java.lang.String typeHandlersPackage)
Packages to search for type handlers.
|
void |
setVfs(java.lang.Class<? extends org.apache.ibatis.io.VFS> vfs)
Sets the VFS.
|
public void setObjectFactory(org.apache.ibatis.reflection.factory.ObjectFactory objectFactory)
objectFactory
- a custom ObjectFactorypublic void setObjectWrapperFactory(org.apache.ibatis.reflection.wrapper.ObjectWrapperFactory objectWrapperFactory)
objectWrapperFactory
- a specified ObjectWrapperFactorypublic org.apache.ibatis.mapping.DatabaseIdProvider getDatabaseIdProvider()
public void setDatabaseIdProvider(org.apache.ibatis.mapping.DatabaseIdProvider databaseIdProvider)
databaseIdProvider
- a DatabaseIdProviderpublic java.lang.Class<? extends org.apache.ibatis.io.VFS> getVfs()
public void setVfs(java.lang.Class<? extends org.apache.ibatis.io.VFS> vfs)
vfs
- a VFSpublic org.apache.ibatis.cache.Cache getCache()
public void setCache(org.apache.ibatis.cache.Cache cache)
cache
- a Cachepublic void setPlugins(org.apache.ibatis.plugin.Interceptor... plugins)
plugins
- list of pluginspublic void setTypeAliasesPackage(java.lang.String typeAliasesPackage)
Since 2.0.1, allow to specify a wildcard such as com.example.*.model
.
typeAliasesPackage
- package to scan for domain objectspublic void setTypeAliasesSuperType(java.lang.Class<?> typeAliasesSuperType)
typeAliasesSuperType
- super class for domain objectspublic void setTypeHandlersPackage(java.lang.String typeHandlersPackage)
Since 2.0.1, allow to specify a wildcard such as com.example.*.typehandler
.
typeHandlersPackage
- package to scan for type handlerspublic void setTypeHandlers(org.apache.ibatis.type.TypeHandler<?>... typeHandlers)
MappedTypes
and optionally with MappedJdbcTypes
typeHandlers
- Type handler listpublic void setTypeAliases(java.lang.Class<?>... typeAliases)
Alias
typeAliases
- Type aliases listpublic void setFailFast(boolean failFast)
failFast
- enable failFastpublic void setConfigLocation(org.springframework.core.io.Resource configLocation)
SqlSessionFactory
config file. A typical value is
"WEB-INF/mybatis-configuration.xml".configLocation
- a location the MyBatis config filepublic void setConfiguration(com.baomidou.mybatisplus.core.MybatisConfiguration configuration)
configuration
- MyBatis configurationpublic com.baomidou.mybatisplus.core.MybatisConfiguration getConfiguration()
public void setMapperLocations(org.springframework.core.io.Resource... mapperLocations)
SqlSessionFactory
configuration
at runtime.
This is an alternative to specifying "<sqlmapper>" entries in an MyBatis config file. This property being based on Spring's resource abstraction also allows for specifying resource patterns here: e.g. "classpath*:sqlmap/*-mapper.xml".
mapperLocations
- location of MyBatis mapper filespublic void setConfigurationProperties(java.util.Properties sqlSessionFactoryProperties)
<properties>
tag in the configuration xml file. This will be used to resolve placeholders in the
config file.sqlSessionFactoryProperties
- optional properties for the SqlSessionFactorypublic void setDataSource(javax.sql.DataSource dataSource)
DataSource
that this instance should manage transactions for. The DataSource
should
match the one used by the SqlSessionFactory
: for example, you could specify the same JNDI DataSource for
both.
A transactional JDBC Connection
for this DataSource
will be provided to application code accessing
this DataSource
directly via DataSourceUtils
or DataSourceTransactionManager
.
The DataSource
specified here should be the target DataSource
to manage transactions for, not a
TransactionAwareDataSourceProxy
. Only data access code may work with
TransactionAwareDataSourceProxy
, while the transaction manager needs to work on the underlying target
DataSource
. If there's nevertheless a TransactionAwareDataSourceProxy
passed in, it will be
unwrapped to extract its target DataSource
.
dataSource
- a JDBC DataSource
public void setTransactionFactory(org.apache.ibatis.transaction.TransactionFactory transactionFactory)
SpringManagedTransactionFactory
The default SpringManagedTransactionFactory
should be appropriate for all cases:
be it Spring transaction management, EJB CMT or plain JTA. If there is no active transaction,
SqlSession operations will execute SQL statements non-transactionally.
It is strongly recommended to use the default TransactionFactory
. If not used, any
attempt at getting an SqlSession through Spring's MyBatis framework will throw an exception if
a transaction is active.
transactionFactory
- the MyBatis TransactionFactorySpringManagedTransactionFactory
public void setScriptingLanguageDrivers(org.apache.ibatis.scripting.LanguageDriver... scriptingLanguageDrivers)
scriptingLanguageDrivers
- scripting language driverspublic void setDefaultScriptingLanguageDriver(java.lang.Class<? extends org.apache.ibatis.scripting.LanguageDriver> defaultScriptingLanguageDriver)
defaultScriptingLanguageDriver
- A default scripting language driver classpublic void afterPropertiesSet() throws java.lang.Exception
afterPropertiesSet
在接口中 org.springframework.beans.factory.InitializingBean
java.lang.Exception
protected org.apache.ibatis.session.SqlSessionFactory buildSqlSessionFactory() throws java.lang.Exception
SqlSessionFactory
instance.
The default implementation uses the standard MyBatis XMLConfigBuilder
API to build a
SqlSessionFactory
instance based on an Reader. Since 1.3.0, it can be specified a
Configuration
instance directly(without config file).
java.io.IOException
- if loading the config file failedjava.lang.Exception
public org.apache.ibatis.session.SqlSessionFactory getObject() throws java.lang.Exception
getObject
在接口中 org.springframework.beans.factory.FactoryBean<org.apache.ibatis.session.SqlSessionFactory>
java.lang.Exception
public java.lang.Class<? extends org.apache.ibatis.session.SqlSessionFactory> getObjectType()
getObjectType
在接口中 org.springframework.beans.factory.FactoryBean<org.apache.ibatis.session.SqlSessionFactory>
public boolean isSingleton()
isSingleton
在接口中 org.springframework.beans.factory.FactoryBean<org.apache.ibatis.session.SqlSessionFactory>
public void onApplicationEvent(org.springframework.context.ApplicationEvent event)
onApplicationEvent
在接口中 org.springframework.context.ApplicationListener<org.springframework.context.ApplicationEvent>
public void setTypeEnumsPackage(java.lang.String typeEnumsPackage)
public void setGlobalConfig(com.baomidou.mybatisplus.core.config.GlobalConfig globalConfig)