类 MybatisSqlSessionFactoryBean
- java.lang.Object
-
- com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean
-
- 所有已实现的接口:
java.util.EventListener,org.springframework.beans.factory.FactoryBean<org.apache.ibatis.session.SqlSessionFactory>,org.springframework.beans.factory.InitializingBean,org.springframework.context.ApplicationListener<org.springframework.context.ApplicationEvent>
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()`
- 从以下版本开始:
- 2017-01-04
- 作者:
- hubin
-
-
构造器概要
构造器 构造器 说明 MybatisSqlSessionFactoryBean()
-
方法概要
所有方法 实例方法 具体方法 已过时的方法 修饰符和类型 方法 说明 voidafterPropertiesSet()protected org.apache.ibatis.session.SqlSessionFactorybuildSqlSessionFactory()Build aSqlSessionFactoryinstance.org.apache.ibatis.cache.CachegetCache()Gets the Cache.com.baomidou.mybatisplus.core.MybatisConfigurationgetConfiguration()org.apache.ibatis.mapping.DatabaseIdProvidergetDatabaseIdProvider()Gets the DatabaseIdProviderorg.apache.ibatis.session.SqlSessionFactorygetObject()java.lang.Class<? extends org.apache.ibatis.session.SqlSessionFactory>getObjectType()java.lang.Class<? extends org.apache.ibatis.io.VFS>getVfs()Gets the VFS.booleanisSingleton()voidonApplicationEvent(org.springframework.context.ApplicationEvent event)voidsetCache(org.apache.ibatis.cache.Cache cache)Sets the Cache.voidsetConfigLocation(org.springframework.core.io.Resource configLocation)Set the location of the MyBatisSqlSessionFactoryconfig file.voidsetConfiguration(com.baomidou.mybatisplus.core.MybatisConfiguration configuration)Set a customized MyBatis configuration.voidsetConfigurationProperties(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.voidsetDatabaseIdProvider(org.apache.ibatis.mapping.DatabaseIdProvider databaseIdProvider)Sets the DatabaseIdProvider.voidsetDataSource(javax.sql.DataSource dataSource)Set the JDBCDataSourcethat this instance should manage transactions for.voidsetDefaultEnumTypeHandler(java.lang.Class<? extends org.apache.ibatis.type.TypeHandler> defaultEnumTypeHandler)Set the default type handler class for enum.voidsetDefaultScriptingLanguageDriver(java.lang.Class<? extends org.apache.ibatis.scripting.LanguageDriver> defaultScriptingLanguageDriver)Set a default scripting language driver class.voidsetFailFast(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.voidsetGlobalConfig(com.baomidou.mybatisplus.core.config.GlobalConfig globalConfig)voidsetMapperLocations(org.springframework.core.io.Resource... mapperLocations)Set locations of MyBatis mapper files that are going to be merged into theSqlSessionFactoryconfiguration at runtime.voidsetObjectFactory(org.apache.ibatis.reflection.factory.ObjectFactory objectFactory)Sets the ObjectFactory.voidsetObjectWrapperFactory(org.apache.ibatis.reflection.wrapper.ObjectWrapperFactory objectWrapperFactory)Sets the ObjectWrapperFactory.voidsetPlugins(org.apache.ibatis.plugin.Interceptor... plugins)Mybatis plugin list.voidsetScriptingLanguageDrivers(org.apache.ibatis.scripting.LanguageDriver... scriptingLanguageDrivers)Set scripting language drivers.voidsetTransactionFactory(org.apache.ibatis.transaction.TransactionFactory transactionFactory)Set the MyBatis TransactionFactory to use.voidsetTypeAliases(java.lang.Class<?>... typeAliases)List of type aliases to register.voidsetTypeAliasesPackage(java.lang.String typeAliasesPackage)Packages to search for type aliases.voidsetTypeAliasesSuperType(java.lang.Class<?> typeAliasesSuperType)Super class which domain objects have to extend to have a type alias created.voidsetTypeEnumsPackage(java.lang.String typeEnumsPackage)已过时。2022-03-07voidsetTypeHandlers(org.apache.ibatis.type.TypeHandler<?>... typeHandlers)Set type handlers.voidsetTypeHandlersPackage(java.lang.String typeHandlersPackage)Packages to search for type handlers.voidsetVfs(java.lang.Class<? extends org.apache.ibatis.io.VFS> vfs)Sets the VFS.
-
-
-
方法详细资料
-
setObjectFactory
public void setObjectFactory(org.apache.ibatis.reflection.factory.ObjectFactory objectFactory)
Sets the ObjectFactory.- 参数:
objectFactory- a custom ObjectFactory- 从以下版本开始:
- 1.1.2
-
setObjectWrapperFactory
public void setObjectWrapperFactory(org.apache.ibatis.reflection.wrapper.ObjectWrapperFactory objectWrapperFactory)
Sets the ObjectWrapperFactory.- 参数:
objectWrapperFactory- a specified ObjectWrapperFactory- 从以下版本开始:
- 1.1.2
-
getDatabaseIdProvider
public org.apache.ibatis.mapping.DatabaseIdProvider getDatabaseIdProvider()
Gets the DatabaseIdProvider- 返回:
- a specified DatabaseIdProvider
- 从以下版本开始:
- 1.1.0
-
setDatabaseIdProvider
public void setDatabaseIdProvider(org.apache.ibatis.mapping.DatabaseIdProvider databaseIdProvider)
Sets the DatabaseIdProvider. As of version 1.2.2 this variable is not initialized by default.- 参数:
databaseIdProvider- a DatabaseIdProvider- 从以下版本开始:
- 1.1.0
-
getVfs
public java.lang.Class<? extends org.apache.ibatis.io.VFS> getVfs()
Gets the VFS.- 返回:
- a specified VFS
-
setVfs
public void setVfs(java.lang.Class<? extends org.apache.ibatis.io.VFS> vfs)
Sets the VFS.- 参数:
vfs- a VFS
-
getCache
public org.apache.ibatis.cache.Cache getCache()
Gets the Cache.- 返回:
- a specified Cache
-
setCache
public void setCache(org.apache.ibatis.cache.Cache cache)
Sets the Cache.- 参数:
cache- a Cache
-
setPlugins
public void setPlugins(org.apache.ibatis.plugin.Interceptor... plugins)
Mybatis plugin list.- 参数:
plugins- list of plugins- 从以下版本开始:
- 1.0.1
-
setTypeAliasesPackage
public void setTypeAliasesPackage(java.lang.String typeAliasesPackage)
Packages to search for type aliases.Since 2.0.1, allow to specify a wildcard such as
com.example.*.model.- 参数:
typeAliasesPackage- package to scan for domain objects- 从以下版本开始:
- 1.0.1
-
setTypeAliasesSuperType
public void setTypeAliasesSuperType(java.lang.Class<?> typeAliasesSuperType)
Super class which domain objects have to extend to have a type alias created. No effect if there is no package to scan configured.- 参数:
typeAliasesSuperType- super class for domain objects- 从以下版本开始:
- 1.1.2
-
setTypeHandlersPackage
public void setTypeHandlersPackage(java.lang.String typeHandlersPackage)
Packages to search for type handlers.Since 2.0.1, allow to specify a wildcard such as
com.example.*.typehandler.- 参数:
typeHandlersPackage- package to scan for type handlers- 从以下版本开始:
- 1.0.1
-
setDefaultEnumTypeHandler
public void setDefaultEnumTypeHandler(java.lang.Class<? extends org.apache.ibatis.type.TypeHandler> defaultEnumTypeHandler)
Set the default type handler class for enum.- 参数:
defaultEnumTypeHandler- The default type handler class for enum- 从以下版本开始:
- 2.0.5
-
setTypeHandlers
public void setTypeHandlers(org.apache.ibatis.type.TypeHandler<?>... typeHandlers)
Set type handlers. They must be annotated withMappedTypesand optionally withMappedJdbcTypes- 参数:
typeHandlers- Type handler list- 从以下版本开始:
- 1.0.1
-
setTypeAliases
public void setTypeAliases(java.lang.Class<?>... typeAliases)
List of type aliases to register. They can be annotated withAlias- 参数:
typeAliases- Type aliases list- 从以下版本开始:
- 1.0.1
-
setFailFast
public 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. Defaults to false.- 参数:
failFast- enable failFast- 从以下版本开始:
- 1.0.1
-
setConfigLocation
public void setConfigLocation(org.springframework.core.io.Resource configLocation)
Set the location of the MyBatisSqlSessionFactoryconfig file. A typical value is "WEB-INF/mybatis-configuration.xml".- 参数:
configLocation- a location the MyBatis config file
-
setConfiguration
public void setConfiguration(com.baomidou.mybatisplus.core.MybatisConfiguration configuration)
Set a customized MyBatis configuration. TODO 这里的入参使用 MybatisConfiguration 而不是 Configuration- 参数:
configuration- MyBatis configuration- 从以下版本开始:
- 1.3.0
-
getConfiguration
public com.baomidou.mybatisplus.core.MybatisConfiguration getConfiguration()
-
setMapperLocations
public void setMapperLocations(org.springframework.core.io.Resource... mapperLocations)
Set locations of MyBatis mapper files that are going to be merged into theSqlSessionFactoryconfiguration 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 files
-
setConfigurationProperties
public 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. This will be used to resolve placeholders in the config file.- 参数:
sqlSessionFactoryProperties- optional properties for the SqlSessionFactory
-
setDataSource
public void setDataSource(javax.sql.DataSource dataSource)
Set the JDBCDataSourcethat this instance should manage transactions for. TheDataSourceshould match the one used by theSqlSessionFactory: for example, you could specify the same JNDI DataSource for both.A transactional JDBC
Connectionfor thisDataSourcewill be provided to application code accessing thisDataSourcedirectly viaDataSourceUtilsorDataSourceTransactionManager.The
DataSourcespecified here should be the targetDataSourceto manage transactions for, not aTransactionAwareDataSourceProxy. Only data access code may work withTransactionAwareDataSourceProxy, while the transaction manager needs to work on the underlying targetDataSource. If there's nevertheless aTransactionAwareDataSourceProxypassed in, it will be unwrapped to extract its targetDataSource.- 参数:
dataSource- a JDBCDataSource
-
setTransactionFactory
public void setTransactionFactory(org.apache.ibatis.transaction.TransactionFactory transactionFactory)
Set the MyBatis TransactionFactory to use. Default isSpringManagedTransactionFactoryThe default
SpringManagedTransactionFactoryshould 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 defaultTransactionFactory. 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 TransactionFactory- 另请参阅:
SpringManagedTransactionFactory
-
setScriptingLanguageDrivers
public void setScriptingLanguageDrivers(org.apache.ibatis.scripting.LanguageDriver... scriptingLanguageDrivers)
Set scripting language drivers.- 参数:
scriptingLanguageDrivers- scripting language drivers- 从以下版本开始:
- 2.0.2
-
setDefaultScriptingLanguageDriver
public void setDefaultScriptingLanguageDriver(java.lang.Class<? extends org.apache.ibatis.scripting.LanguageDriver> defaultScriptingLanguageDriver)
Set a default scripting language driver class.- 参数:
defaultScriptingLanguageDriver- A default scripting language driver class- 从以下版本开始:
- 2.0.2
-
afterPropertiesSet
public void afterPropertiesSet() throws java.lang.Exception- 指定者:
afterPropertiesSet在接口中org.springframework.beans.factory.InitializingBean- 抛出:
java.lang.Exception
-
buildSqlSessionFactory
protected org.apache.ibatis.session.SqlSessionFactory buildSqlSessionFactory() throws java.lang.ExceptionBuild aSqlSessionFactoryinstance.The default implementation uses the standard MyBatis
XMLConfigBuilderAPI to build aSqlSessionFactoryinstance based on an Reader. Since 1.3.0, it can be specified aConfigurationinstance directly(without config file).- 返回:
- SqlSessionFactory
- 抛出:
java.io.IOException- if loading the config file failedjava.lang.Exception
-
getObject
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
-
getObjectType
public java.lang.Class<? extends org.apache.ibatis.session.SqlSessionFactory> getObjectType()
- 指定者:
getObjectType在接口中org.springframework.beans.factory.FactoryBean<org.apache.ibatis.session.SqlSessionFactory>
-
isSingleton
public boolean isSingleton()
- 指定者:
isSingleton在接口中org.springframework.beans.factory.FactoryBean<org.apache.ibatis.session.SqlSessionFactory>
-
onApplicationEvent
public void onApplicationEvent(org.springframework.context.ApplicationEvent event)
- 指定者:
onApplicationEvent在接口中org.springframework.context.ApplicationListener<org.springframework.context.ApplicationEvent>
-
setTypeEnumsPackage
@Deprecated public void setTypeEnumsPackage(java.lang.String typeEnumsPackage)
已过时。2022-03-07不再需要这个配置,放心删除
-
setGlobalConfig
public void setGlobalConfig(com.baomidou.mybatisplus.core.config.GlobalConfig globalConfig)
-
-