Spring关闭错误:java.lang.NoClassDefFoundError: org/apache/log4j/spi/ThrowableInformation
/把博客改成热部署后,每次更新class文件后,服务器关闭会出现如下错误:
[14:40:28.434] java.lang.NoClassDefFoundError: org/apache/log4j/spi/ThrowableInformation
[14:40:28.434] at org.apache.log4j.spi.LoggingEvent.<init>(LoggingEvent.java:154)
[14:40:28.434] at org.apache.log4j.Category.forcedLog(Category.java:388)
[14:40:28.434] at org.apache.log4j.Category.log(Category.java:853)
[14:40:28.434] at org.apache.commons.logging.impl.Log4JLogger.error(Log4JLogger.java:251)
[14:40:28.434] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroyBean(DefaultSingletonBeanRegistry.java:513)
[14:40:28.434] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingleton(DefaultSingletonBeanRegistry.java:486)
[14:40:28.434] at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingleton(DefaultListableBeanFactory.java:742)
[14:40:28.434] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingletons(DefaultSingletonBeanRegistry.java:455)
[14:40:28.434] at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:1090)
[14:40:28.434] at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:1064)
[14:40:28.434] at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:1010)
[14:40:28.434] at org.springframework.web.context.ContextLoader.closeWebApplicationContext(ContextLoader.java:586)
[14:40:28.434] at org.springframework.web.context.ContextLoaderListener.contextDestroyed(ContextLoaderListener.java:143)
[14:40:28.434] at com.caucho.server.webapp.Application.stop(Application.java:2436)
[14:40:28.434] at com.caucho.server.webapp.Application.destroy(Application.java:2459)
[14:40:28.434] at com.caucho.server.deploy.DeployController.stopImpl(DeployController.java:703)
[14:40:28.434] at com.caucho.server.deploy.DeployController.restartImpl(DeployController.java:582)
[14:40:28.434] at com.caucho.server.deploy.StartAutoRedeployAutoStrategy.alarm(StartAutoRedeployAutoStrategy.java:176)
[14:40:28.434] at com.caucho.server.deploy.DeployController.handleAlarm(DeployController.java:742)
[14:40:28.434] at com.caucho.util.Alarm.handleAlarm(Alarm.java:339)
[14:40:28.434] at com.caucho.util.Alarm.run(Alarm.java:309)
[14:40:28.434] at com.caucho.util.ThreadPool.runTasks(ThreadPool.java:527)
[14:40:28.434] at com.caucho.util.ThreadPool.run(ThreadPool.java:449)
[14:40:28.434] at java.lang.Thread.run(Thread.java:662)
[15:05:09.848] Server[] stopping
[15:05:09.866] Received close event
熟悉Spring源码的程序员会知道,这是spring扫描的DefaultListableBeanFactory关闭后,要关闭相应的bean出现的错误。
异常也给了很好的提示,就是没有发现类:
ThrowableInformation
研究工程的mvn tree,发现有
org.slf4jslf4j-log4j121.5.6
依赖了log4j版本:
[INFO] +- org.slf4j:slf4j-log4j12:jar:1.5.6:compile
[INFO] | \- org.slf4j:slf4j-api:jar:1.5.6:compile
[INFO] +- log4j:log4j:jar:1.2.17:compile
1.2.16以上版本才包含了ThrowableInformation
加入相应的pom依赖:
log4jlog4j1.2.17
再次热部署,成功,bug消失。
[15:08:24.601] Reloading com.li5jun.blog.velocity.VelocityViewRender
... ...
[15:08:24.693] Reloading com.li5jun.blog.service.impl.BlogServiceImpl