类 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
    • 字段概要

      • 从接口继承的字段 org.springframework.beans.factory.FactoryBean

        OBJECT_TYPE_ATTRIBUTE
    • 方法概要

      所有方法 实例方法 具体方法 已过时的方法 
      修饰符和类型 方法 说明
      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 &lt;properties&gt; 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 setDefaultEnumTypeHandler​(java.lang.Class<? extends org.apache.ibatis.type.TypeHandler> defaultEnumTypeHandler)
      Set the default type handler class for enum.
      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)
      已过时。
      2022-03-07
      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.
      • 从类继承的方法 java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 构造器详细资料

      • MybatisSqlSessionFactoryBean

        public MybatisSqlSessionFactoryBean()
    • 方法详细资料

      • 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 with MappedTypes and optionally with MappedJdbcTypes
        参数:
        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 with Alias
        参数:
        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 MyBatis SqlSessionFactory config 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 the 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 files
      • setConfigurationProperties

        public void setConfigurationProperties​(java.util.Properties sqlSessionFactoryProperties)
        Set optional properties to be passed into the SqlSession configuration, as alternative to a &lt;properties&gt; 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 JDBC 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
      • setTransactionFactory

        public void setTransactionFactory​(org.apache.ibatis.transaction.TransactionFactory transactionFactory)
        Set the MyBatis TransactionFactory to use. Default is 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 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.Exception
        Build a 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).

        返回:
        SqlSessionFactory
        抛出:
        java.io.IOException - if loading the config file failed
        java.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)