In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the SqlSessionFactory problem and how to deal with it when using Mybatis-Plus. The content is very detailed. Interested friends can use it for reference. I hope it will be helpful to you.
SqlSessionFactory problems when using Mybatis-Plus
A few days ago, there was a problem in my work. MybatisPlus was used in the project, and then there was a problem. Other configurations of Druid can be used normally, but the bean of the configured SqlSessionFactory cannot be loaded, and the mybatis-config.xml file I loaded in this bean cannot be loaded, because the code uses an interceptor for automatic paging of the database. Find the problem and mark it here.
In fact, the reason why this cannot be loaded is that MybatisSqlSessionFactoryBean is customized in MybatisPlus, and this class implements interfaces FactoryBean, InitializingBean, ApplicationListener, and there is a class in mybatis that also implements these interfaces, SqlSessionFactoryBean, so when configuring SqlSessionFactoryBean in the mybatisplus configuration file, you need to change to the custom class MyBatisSqlSessionFactoryBean in mybatisplus, and load the corresponding mybatis-config.xml file in the class.
Paste the source code of these two classes and you can see / Source code recreated from a .class file by IntelliJ IDEA// (powered by Fernflower decompiler) / / package org.mybatis.spring;import java.io.IOException;import java.sql.SQLException;import java.util.Properties;import javax.sql.DataSource;import org.apache.ibatis.builder.xml.XMLConfigBuilder;import org.apache.ibatis.builder.xml.XMLMapperBuilder;import org.apache.ibatis.cache.Cache;import org.apache.ibatis.executor.ErrorContext Import org.apache.ibatis.io.VFS;import org.apache.ibatis.logging.Log;import org.apache.ibatis.logging.LogFactory;import org.apache.ibatis.mapping.DatabaseIdProvider;import org.apache.ibatis.mapping.Environment;import org.apache.ibatis.plugin.Interceptor;import org.apache.ibatis.reflection.factory.ObjectFactory;import org.apache.ibatis.reflection.wrapper.ObjectWrapperFactory;import org.apache.ibatis.session.Configuration;import org.apache.ibatis.session.SqlSessionFactory;import org.apache.ibatis.session.SqlSessionFactoryBuilder Import org.apache.ibatis.transaction.TransactionFactory;import org.apache.ibatis.type.TypeHandler;import org.mybatis.spring.transaction.SpringManagedTransactionFactory;import org.springframework.beans.factory.FactoryBean;import org.springframework.beans.factory.InitializingBean;import org.springframework.context.ApplicationEvent;import org.springframework.context.ApplicationListener;import org.springframework.context.event.ContextRefreshedEvent;import org.springframework.core.NestedIOException;import org.springframework.core.io.Resource;import org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy;import org.springframework.util.Assert Import org.springframework.util.ObjectUtils;import org.springframework.util.StringUtils;public class SqlSessionFactoryBean implements FactoryBean, InitializingBean, ApplicationListener {private static final Log LOGGER = LogFactory.getLog (SqlSessionFactoryBean.class); private Resource configLocation; private Configuration configuration; private Resource [] mapperLocations; private DataSource dataSource; private TransactionFactory transactionFactory; private Properties configurationProperties; private SqlSessionFactoryBuilder sqlSessionFactoryBuilder = new SqlSessionFactoryBuilder (); private SqlSessionFactory sqlSessionFactory; private String environment = SqlSessionFactoryBean.class.getSimpleName (); private boolean failFast; private Interceptor [] plugins Private TypeHandler [] typeHandlers; private String typeHandlersPackage; private Class [] typeAliases; private String typeAliasesPackage; private Class typeAliasesSuperType; private DatabaseIdProvider databaseIdProvider; private Class [] typeHandlers; private String typeHandlersPackage; private Class [] typeAliases; private String typeAliasesPackage; private String typeEnumsPackage; private Class typeAliasesSuperType; private DatabaseIdProvider databaseIdProvider; private Class
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.