• Could not initialize class org.apache.log4j.LogManager 报错


    部署项目的时候,在windows下一切正常,但是在centos下就发生如下错误

    Caused by: java.lang.ExceptionInInitializerError
        at com.dsideal.sys.service.impl.SysMenuService.<init>(SysMenuService.java:60)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
        at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:96)
        ... 32 more
    Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'LoggingThrowsAdvice' defined in class path resource [applicationContext.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.dsideal.framework.aop.LoggingThrowsAdvice]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: Could not initialize class org.apache.log4j.LogManager
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:881)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:837)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:440)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
        at java.security.AccessController.doPrivileged(Native Method)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:220)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:429)
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:729)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:381)
        at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
        at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
        at com.dsideal.framework.common.SpringUtil.<clinit>(SpringUtil.java:9)
        ... 38 more
    Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.dsideal.framework.aop.LoggingThrowsAdvice]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: Could not initialize class org.apache.log4j.LogManager
        at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:111)
        at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:61)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:875)
        ... 54 more
    Caused by: java.lang.NoClassDefFoundError: Could not initialize class org.apache.log4j.LogManager
        at org.apache.log4j.Logger.getLogger(Logger.java:85)
        at com.dsideal.framework.aop.LoggingThrowsAdvice.<init>(LoggingThrowsAdvice.java:12)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
        at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:96)
        ... 56 more

    最终解决方法是:log4j.properties配置错误

    windows下配置为:

    #log4j.rootLogger=info,stdout
    log4j.appender.stdout=org.apache.log4j.ConsoleAppender
    log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
    log4j.appender.stdout.layout.conversionPattern=%5p [%t] - %m%n
    #
    log4j.appender.file=org.apache.log4j.RollingFileAppender
    log4j.appender.file.File=c:/subject.log
    log4j.appender.file.MaxFileSize=100KB
    log4j.appender.file.MaxBackupIndex=0
    log4j.appender.file.layout=org.apache.log4j.SimpleLayout
    log4j.appender.file.layout.ConversionPattern=[ssh] %p %t %c - %m%n
    #
    log4j.logger.com.ibatis=debug,ibatis
    log4j.logger.com.ibatis.common.jdbc.SimpleDataSource=debug,ibatis
    log4j.logger.com.ibatis.common.jdbc.ScriptRunner=debug,ibatis
    log4j.logger.com.ibatis.sqlmap.engine.impl.SqlMapClientDelegate=debug,ibatis
    #
    log4j.logger.java.sql.Connection=debug,ibatis
    log4j.logger.java.sql.Statement=debug,ibatis
    log4j.logger.java.sql.PreparedStatement=debug,stdout,ibatis
    log4j.logger.java.lang.Exception=debug,ibatis
    #
    log4j.appender.ibatis=org.apache.log4j.RollingFileAppender
    log4j.appender.ibatis.File=c:/ibatis.log
    log4j.appender.ibatis.MaxFileSize=100KB
    log4j.appender.ibatis.MaxBackupIndex=0
    log4j.appender.ibatis.layout=org.apache.log4j.SimpleLayout
    log4j.appender.ibatis.layout.ConversionPattern=[ssh] %p %t %c - %m%n
    
    log4j.logger.com.opensymphony.xwork2=ERROR

    而在centos中,没有c:/,这里一定要注意

    #log4j.rootLogger=info,stdout
    log4j.appender.stdout=org.apache.log4j.ConsoleAppender
    log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
    log4j.appender.stdout.layout.conversionPattern=%5p [%t] - %m%n
    #
    log4j.appender.file=org.apache.log4j.RollingFileAppender
    log4j.appender.file.File=/usr/local/subject.log
    log4j.appender.file.MaxFileSize=100KB
    log4j.appender.file.MaxBackupIndex=0
    log4j.appender.file.layout=org.apache.log4j.SimpleLayout
    log4j.appender.file.layout.ConversionPattern=[ssh] %p %t %c - %m%n
    #
    log4j.logger.com.ibatis=debug,ibatis
    log4j.logger.com.ibatis.common.jdbc.SimpleDataSource=debug,ibatis
    log4j.logger.com.ibatis.common.jdbc.ScriptRunner=debug,ibatis
    log4j.logger.com.ibatis.sqlmap.engine.impl.SqlMapClientDelegate=debug,ibatis
    #
    log4j.logger.java.sql.Connection=debug,ibatis
    log4j.logger.java.sql.Statement=debug,ibatis
    log4j.logger.java.sql.PreparedStatement=debug,stdout,ibatis
    log4j.logger.java.lang.Exception=debug,ibatis
    #
    log4j.appender.ibatis=org.apache.log4j.RollingFileAppender
    log4j.appender.ibatis.File=/usr/local/ibatis.log
    log4j.appender.ibatis.MaxFileSize=100KB
    log4j.appender.ibatis.MaxBackupIndex=0
    log4j.appender.ibatis.layout=org.apache.log4j.SimpleLayout
    log4j.appender.ibatis.layout.ConversionPattern=[ssh] %p %t %c - %m%n
    
    log4j.logger.com.opensymphony.xwork2=ERROR
  • 相关阅读:
    Java EE (3) -- Java EE 6 Web Services Developer Certified Expert(1z0-897)
    二、用电信号传输 TCP/IP 数据(1)
    P2384 最短路 洛谷
    T1231 最优布线 codevs
    P3371 单源最短路径【模板】 洛谷
    spfa【模板】
    P1396 营救 洛谷
    解决Android加固多进程ptrace反调试的思路整理
    Android Dex文件格式解析
    360加固保so动态脱壳
  • 原文地址:https://www.cnblogs.com/cczhoufeng/p/3165751.html
Copyright © 2020-2023  润新知