兼容springboot 1.5.22

This commit is contained in:
admin 2021-05-18 16:00:13 +08:00
parent 83bfea17bc
commit 1af431641f

View File

@ -8,6 +8,7 @@ import org.apache.ibatis.plugin.InterceptorChain;
import org.apache.ibatis.session.Configuration; import org.apache.ibatis.session.Configuration;
import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.boot.context.event.ApplicationStartedEvent; import org.springframework.boot.context.event.ApplicationStartedEvent;
import org.springframework.context.ApplicationListener; import org.springframework.context.ApplicationListener;
@ -20,7 +21,7 @@ import java.util.List;
* *
* @author yulichang * @author yulichang
*/ */
public class InterceptorConfig implements ApplicationListener<ApplicationStartedEvent> { public class InterceptorConfig implements ApplicationListener<ApplicationReadyEvent> {
@Autowired @Autowired
private List<SqlSessionFactory> sqlSessionFactoryList; private List<SqlSessionFactory> sqlSessionFactoryList;
@ -29,10 +30,14 @@ public class InterceptorConfig implements ApplicationListener<ApplicationStarted
@Override @Override
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void onApplicationEvent(ApplicationStartedEvent event) { public void onApplicationEvent(ApplicationReadyEvent event) {
System.out.println("werwerewqrweqtwtrwqt\n\newqwerw\n\n");
if (CollectionUtils.isNotEmpty(sqlSessionFactoryList)) { if (CollectionUtils.isNotEmpty(sqlSessionFactoryList)) {
try { try {
for (SqlSessionFactory factory : sqlSessionFactoryList) { for (SqlSessionFactory factory : sqlSessionFactoryList) {
System.out.println("WWwwwwwwwwwwwwwwwwwwww");
System.out.println("\n\n\n\n\n");
System.out.println("wwwwwwwwwwwwwwwwwwwwwwwwwwwww");
Field interceptorChain = Configuration.class.getDeclaredField("interceptorChain"); Field interceptorChain = Configuration.class.getDeclaredField("interceptorChain");
interceptorChain.setAccessible(true); interceptorChain.setAccessible(true);
InterceptorChain chain = (InterceptorChain) interceptorChain.get(factory.getConfiguration()); InterceptorChain chain = (InterceptorChain) interceptorChain.get(factory.getConfiguration());