public class FlexSqlSessionFactoryBean extends org.mybatis.spring.SqlSessionFactoryBean implements org.springframework.beans.factory.FactoryBean<org.apache.ibatis.session.SqlSessionFactory>, org.springframework.beans.factory.InitializingBean, org.springframework.context.ApplicationListener<org.springframework.context.event.ContextRefreshedEvent>
在 MyBatis 官方的 SqlSessionFactoryBean 基础上,替换了 FlexSqlSessionFactoryBean。
源于 SqlSessionFactoryBean,主要是用于构建 FlexConfiguration,而不是使用原生的 Configuration。
此代码主要是用于修改 buildSqlSessionFactory() 部分。
| 限定符和类型 | 字段和说明 |
|---|---|
private org.apache.ibatis.cache.Cache |
cache |
private org.springframework.core.io.Resource |
configLocation |
private org.apache.ibatis.session.Configuration |
configuration |
private Properties |
configurationProperties |
private org.apache.ibatis.mapping.DatabaseIdProvider |
databaseIdProvider |
private DataSource |
dataSource |
private Class<? extends org.apache.ibatis.type.TypeHandler> |
defaultEnumTypeHandler |
private Class<? extends org.apache.ibatis.scripting.LanguageDriver> |
defaultScriptingLanguageDriver |
private String |
environment |
private boolean |
failFast |
private static org.mybatis.logging.Logger |
LOGGER |
private org.springframework.core.io.Resource[] |
mapperLocations |
private static org.springframework.core.type.classreading.MetadataReaderFactory |
METADATA_READER_FACTORY |
private org.apache.ibatis.reflection.factory.ObjectFactory |
objectFactory |
private org.apache.ibatis.reflection.wrapper.ObjectWrapperFactory |
objectWrapperFactory |
private static String |
P6SPY_DATA_SOURCE_CLASS |
private org.apache.ibatis.plugin.Interceptor[] |
plugins |
private static org.springframework.core.io.support.ResourcePatternResolver |
RESOURCE_PATTERN_RESOLVER |
private org.apache.ibatis.scripting.LanguageDriver[] |
scriptingLanguageDrivers |
private org.apache.ibatis.session.SqlSessionFactory |
sqlSessionFactory |
private org.apache.ibatis.session.SqlSessionFactoryBuilder |
sqlSessionFactoryBuilder |
private org.apache.ibatis.transaction.TransactionFactory |
transactionFactory |
private Class<?>[] |
typeAliases |
private String |
typeAliasesPackage |
private Class<?> |
typeAliasesSuperType |
private org.apache.ibatis.type.TypeHandler<?>[] |
typeHandlers |
private String |
typeHandlersPackage |
private Class<? extends org.apache.ibatis.io.VFS> |
vfs |
| 构造器和说明 |
|---|
FlexSqlSessionFactoryBean() |
| 限定符和类型 | 方法和说明 |
|---|---|
void |
afterPropertiesSet() |
protected org.apache.ibatis.session.SqlSessionFactory |
buildSqlSessionFactory()
Build a
SqlSessionFactory instance. |
org.apache.ibatis.cache.Cache |
getCache()
Gets the Cache.
|
org.apache.ibatis.mapping.DatabaseIdProvider |
getDatabaseIdProvider()
Gets the DatabaseIdProvider
|
org.apache.ibatis.session.SqlSessionFactory |
getObject() |
Class<? extends org.apache.ibatis.session.SqlSessionFactory> |
getObjectType() |
Class<? extends org.apache.ibatis.io.VFS> |
getVfs()
Gets the VFS.
|
boolean |
isSingleton() |
void |
onApplicationEvent(org.springframework.context.event.ContextRefreshedEvent event) |
private Set<Class<?>> |
scanClasses(String packagePatterns,
Class<?> assignableType) |
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(org.apache.ibatis.session.Configuration configuration)
Set a customized MyBatis configuration.
|
void |
setConfigurationProperties(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(DataSource dataSource)
Set the JDBC
DataSource that this instance should manage transactions for. |
void |
setDefaultEnumTypeHandler(Class<? extends org.apache.ibatis.type.TypeHandler> defaultEnumTypeHandler)
Set the default type handler class for enum.
|
void |
setDefaultScriptingLanguageDriver(Class<? extends org.apache.ibatis.scripting.LanguageDriver> defaultScriptingLanguageDriver)
Set a default scripting language driver class.
|
void |
setEnvironment(String environment)
NOTE: This class overrides any
Environment you have set in the MyBatis config file. |
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 |
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 |
setSqlSessionFactoryBuilder(org.apache.ibatis.session.SqlSessionFactoryBuilder sqlSessionFactoryBuilder)
Sets the
SqlSessionFactoryBuilder to use when creating the SqlSessionFactory. |
void |
setTransactionFactory(org.apache.ibatis.transaction.TransactionFactory transactionFactory)
Set the MyBatis TransactionFactory to use.
|
void |
setTypeAliases(Class<?>... typeAliases)
List of type aliases to register.
|
void |
setTypeAliasesPackage(String typeAliasesPackage)
Packages to search for type aliases.
|
void |
setTypeAliasesSuperType(Class<?> typeAliasesSuperType)
Super class which domain objects have to extend to have a type alias created.
|
void |
setTypeHandlers(org.apache.ibatis.type.TypeHandler<?>... typeHandlers)
Set type handlers.
|
void |
setTypeHandlersPackage(String typeHandlersPackage)
Packages to search for type handlers.
|
void |
setVfs(Class<? extends org.apache.ibatis.io.VFS> vfs)
Sets the VFS.
|
addMapperLocations, addPlugins, addScriptingLanguageDrivers, addTypeAliases, addTypeHandlersprivate static final org.mybatis.logging.Logger LOGGER
private static final String P6SPY_DATA_SOURCE_CLASS
private static final org.springframework.core.io.support.ResourcePatternResolver RESOURCE_PATTERN_RESOLVER
private static final org.springframework.core.type.classreading.MetadataReaderFactory METADATA_READER_FACTORY
private org.springframework.core.io.Resource configLocation
private org.apache.ibatis.session.Configuration configuration
private org.springframework.core.io.Resource[] mapperLocations
private DataSource dataSource
private org.apache.ibatis.transaction.TransactionFactory transactionFactory
private Properties configurationProperties
private org.apache.ibatis.session.SqlSessionFactoryBuilder sqlSessionFactoryBuilder
private org.apache.ibatis.session.SqlSessionFactory sqlSessionFactory
private String environment
private boolean failFast
private org.apache.ibatis.plugin.Interceptor[] plugins
private org.apache.ibatis.type.TypeHandler<?>[] typeHandlers
private String typeHandlersPackage
private Class<? extends org.apache.ibatis.type.TypeHandler> defaultEnumTypeHandler
private Class<?>[] typeAliases
private String typeAliasesPackage
private Class<?> typeAliasesSuperType
private org.apache.ibatis.scripting.LanguageDriver[] scriptingLanguageDrivers
private Class<? extends org.apache.ibatis.scripting.LanguageDriver> defaultScriptingLanguageDriver
private org.apache.ibatis.mapping.DatabaseIdProvider databaseIdProvider
private org.apache.ibatis.cache.Cache cache
private org.apache.ibatis.reflection.factory.ObjectFactory objectFactory
private org.apache.ibatis.reflection.wrapper.ObjectWrapperFactory objectWrapperFactory
public FlexSqlSessionFactoryBean()
public void setObjectFactory(org.apache.ibatis.reflection.factory.ObjectFactory objectFactory)
setObjectFactory 在类中 org.mybatis.spring.SqlSessionFactoryBeanobjectFactory - a custom ObjectFactorypublic void setObjectWrapperFactory(org.apache.ibatis.reflection.wrapper.ObjectWrapperFactory objectWrapperFactory)
setObjectWrapperFactory 在类中 org.mybatis.spring.SqlSessionFactoryBeanobjectWrapperFactory - a specified ObjectWrapperFactorypublic org.apache.ibatis.mapping.DatabaseIdProvider getDatabaseIdProvider()
getDatabaseIdProvider 在类中 org.mybatis.spring.SqlSessionFactoryBeanpublic void setDatabaseIdProvider(org.apache.ibatis.mapping.DatabaseIdProvider databaseIdProvider)
setDatabaseIdProvider 在类中 org.mybatis.spring.SqlSessionFactoryBeandatabaseIdProvider - a DatabaseIdProviderpublic Class<? extends org.apache.ibatis.io.VFS> getVfs()
getVfs 在类中 org.mybatis.spring.SqlSessionFactoryBeanpublic void setVfs(Class<? extends org.apache.ibatis.io.VFS> vfs)
setVfs 在类中 org.mybatis.spring.SqlSessionFactoryBeanvfs - a VFSpublic org.apache.ibatis.cache.Cache getCache()
getCache 在类中 org.mybatis.spring.SqlSessionFactoryBeanpublic void setCache(org.apache.ibatis.cache.Cache cache)
setCache 在类中 org.mybatis.spring.SqlSessionFactoryBeancache - a Cachepublic void setPlugins(org.apache.ibatis.plugin.Interceptor... plugins)
setPlugins 在类中 org.mybatis.spring.SqlSessionFactoryBeanplugins - list of pluginspublic void setTypeAliasesPackage(String typeAliasesPackage)
Since 2.0.1, allow to specify a wildcard such as com.example.*.model.
setTypeAliasesPackage 在类中 org.mybatis.spring.SqlSessionFactoryBeantypeAliasesPackage - package to scan for domain objectspublic void setTypeAliasesSuperType(Class<?> typeAliasesSuperType)
setTypeAliasesSuperType 在类中 org.mybatis.spring.SqlSessionFactoryBeantypeAliasesSuperType - super class for domain objectspublic void setTypeHandlersPackage(String typeHandlersPackage)
Since 2.0.1, allow to specify a wildcard such as com.example.*.typehandler.
setTypeHandlersPackage 在类中 org.mybatis.spring.SqlSessionFactoryBeantypeHandlersPackage - package to scan for type handlerspublic void setTypeHandlers(org.apache.ibatis.type.TypeHandler<?>... typeHandlers)
MappedTypes and optionally with MappedJdbcTypessetTypeHandlers 在类中 org.mybatis.spring.SqlSessionFactoryBeantypeHandlers - Type handler listpublic void setDefaultEnumTypeHandler(Class<? extends org.apache.ibatis.type.TypeHandler> defaultEnumTypeHandler)
setDefaultEnumTypeHandler 在类中 org.mybatis.spring.SqlSessionFactoryBeandefaultEnumTypeHandler - The default type handler class for enumpublic void setTypeAliases(Class<?>... typeAliases)
AliassetTypeAliases 在类中 org.mybatis.spring.SqlSessionFactoryBeantypeAliases - Type aliases listpublic void setFailFast(boolean failFast)
setFailFast 在类中 org.mybatis.spring.SqlSessionFactoryBeanfailFast - enable failFastpublic void setConfigLocation(org.springframework.core.io.Resource configLocation)
SqlSessionFactory config file. A typical value is
"WEB-INF/mybatis-configuration.xml".setConfigLocation 在类中 org.mybatis.spring.SqlSessionFactoryBeanconfigLocation - a location the MyBatis config filepublic void setConfiguration(org.apache.ibatis.session.Configuration configuration)
setConfiguration 在类中 org.mybatis.spring.SqlSessionFactoryBeanconfiguration - MyBatis configurationpublic 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".
setMapperLocations 在类中 org.mybatis.spring.SqlSessionFactoryBeanmapperLocations - location of MyBatis mapper filespublic void setConfigurationProperties(Properties sqlSessionFactoryProperties)
<properties> tag in the configuration xml file. This will be used to resolve placeholders in the
config file.setConfigurationProperties 在类中 org.mybatis.spring.SqlSessionFactoryBeansqlSessionFactoryProperties - optional properties for the SqlSessionFactorypublic void setDataSource(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.
setDataSource 在类中 org.mybatis.spring.SqlSessionFactoryBeandataSource - a JDBC DataSourcepublic void setSqlSessionFactoryBuilder(org.apache.ibatis.session.SqlSessionFactoryBuilder sqlSessionFactoryBuilder)
SqlSessionFactoryBuilder to use when creating the SqlSessionFactory.
This is mainly meant for testing so that mock SqlSessionFactory classes can be injected. By default,
SqlSessionFactoryBuilder creates DefaultSqlSessionFactory instances.
setSqlSessionFactoryBuilder 在类中 org.mybatis.spring.SqlSessionFactoryBeansqlSessionFactoryBuilder - a SqlSessionFactoryBuilderpublic 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.
setTransactionFactory 在类中 org.mybatis.spring.SqlSessionFactoryBeantransactionFactory - the MyBatis TransactionFactorySpringManagedTransactionFactorypublic void setEnvironment(String environment)
Environment you have set in the MyBatis config file. This is
used only as a placeholder name. The default value is SqlSessionFactoryBean.class.getSimpleName().setEnvironment 在类中 org.mybatis.spring.SqlSessionFactoryBeanenvironment - the environment namepublic void setScriptingLanguageDrivers(org.apache.ibatis.scripting.LanguageDriver... scriptingLanguageDrivers)
setScriptingLanguageDrivers 在类中 org.mybatis.spring.SqlSessionFactoryBeanscriptingLanguageDrivers - scripting language driverspublic void setDefaultScriptingLanguageDriver(Class<? extends org.apache.ibatis.scripting.LanguageDriver> defaultScriptingLanguageDriver)
setDefaultScriptingLanguageDriver 在类中 org.mybatis.spring.SqlSessionFactoryBeandefaultScriptingLanguageDriver - A default scripting language driver classpublic void afterPropertiesSet() throws Exception
afterPropertiesSet 在接口中 org.springframework.beans.factory.InitializingBeanafterPropertiesSet 在类中 org.mybatis.spring.SqlSessionFactoryBeanExceptionprotected org.apache.ibatis.session.SqlSessionFactory buildSqlSessionFactory() throws Exception
SqlSessionFactory instance.
The default implementation uses the standard MyBatis XMLConfigBuilder API to build a
SqlSessionFactory instance based on a Reader. Since 1.3.0, it can be specified a Configuration
instance directly(without config file).
buildSqlSessionFactory 在类中 org.mybatis.spring.SqlSessionFactoryBeanException - if configuration is failedpublic org.apache.ibatis.session.SqlSessionFactory getObject() throws Exception
getObject 在接口中 org.springframework.beans.factory.FactoryBean<org.apache.ibatis.session.SqlSessionFactory>getObject 在类中 org.mybatis.spring.SqlSessionFactoryBeanExceptionpublic Class<? extends org.apache.ibatis.session.SqlSessionFactory> getObjectType()
getObjectType 在接口中 org.springframework.beans.factory.FactoryBean<org.apache.ibatis.session.SqlSessionFactory>getObjectType 在类中 org.mybatis.spring.SqlSessionFactoryBeanpublic boolean isSingleton()
isSingleton 在接口中 org.springframework.beans.factory.FactoryBean<org.apache.ibatis.session.SqlSessionFactory>isSingleton 在类中 org.mybatis.spring.SqlSessionFactoryBeanpublic void onApplicationEvent(org.springframework.context.event.ContextRefreshedEvent event)
onApplicationEvent 在接口中 org.springframework.context.ApplicationListener<org.springframework.context.event.ContextRefreshedEvent>onApplicationEvent 在类中 org.mybatis.spring.SqlSessionFactoryBeanprivate Set<Class<?>> scanClasses(String packagePatterns, Class<?> assignableType) throws IOException
IOExceptionCopyright © 2025. All rights reserved.