目录
1. 问题描述
2. 问题排查
springboot 2.0.4
通过 springboot 内置 tomcat 启动服务无异常,但是使用外置 tomcat 启动报错,错误信息如下:
Caused by: java.lang.AbstractMethodError: org.apache.logging.log4j.core.config.ConfigurationFactory.getConfiguration(Lorg/apache/logging/log4j/core/config/ConfigurationSource;)Lorg/apache/logging/log4j/core/config/Configuration; at org.apache.logging.log4j.core.config.ConfigurationFactory$Factory.getConfiguration(ConfigurationFactory.java:509) at org.apache.logging.log4j.core.config.ConfigurationFactory$Factory.getConfiguration(ConfigurationFactory.java:449) at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:237) at org.apache.logging.log4j.core.config.Configurator.initialize(Configurator.java:157) at org.apache.logging.log4j.web.Log4jWebInitializerImpl.initializeNonJndi(Log4jWebInitializerImpl.java:168) at org.apache.logging.log4j.web.Log4jWebInitializerImpl.start(Log4jWebInitializerImpl.java:110) at org.apache.logging.log4j.web.Log4jServletContainerInitializer.onStartup(Log4jServletContainerInitializer.java:57) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5225) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) ... 44 more
看报错信息,是实现抽象方法遇到了问题,初步怀疑是版本的问题。
找到报错的位置,通过 debug 发现,是在调用 SpringBootConfigurationFactory 类的 getConfiguration 方法的时候抛出了异常。看到确实是在实现这个抽象方法的时候出现了异常,ConfigurationFactory 是在 log4j-core 里面,所以升级了 log4j 的版本,从 2.6.2 升级到 2.7.0,解决了这个问题。