• log4j-over-slf4j.jar AND slf4j-log4j12.jar 依赖冲突解决方案


    使用maven构建项目时,如果项目中有log4j的依赖,在运行程序时可能会出现在同一个类中log4j-over-slf4j.jar和 slf4j-log4j12.jar冲突的问题:


    项目报错内容为:

    Exception in thread "main" java.lang.ExceptionInInitializerError
        at org.apache.log4j.LogManager.getLogger(LogManager.java:44)
        at org.slf4j.impl.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:66)
        at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:270)
        at org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:155)
        at org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:132)
        at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:657)
        at org.apache.hadoop.conf.Configuration.<clinit>(Configuration.java:173)

    Caused by: java.lang.IllegalStateException: Detected both log4j-over-slf4j.jar AND slf4j-log4j12.jar on the class path, preempting StackOverflowError. See also http://www.slf4j.org/codes.html#log4jDelegationLoop for more details.
        at org.apache.log4j.Log4jLoggerFactory.<clinit>(Log4jLoggerFactory.java:49)
        ... 8 more

    原因是:log4j-over-slf4j和slf4j-log4j12是跟Java日志系统相关的两个jar包,当它们同时出现在classpath下时,就可能会引起堆栈溢出异常。


    解决办法:pom.xml文件中,在使用到的依赖包中添加<exclusion>标签将slf4j-log4j12.jar排除即可:


    例如:红色字体是排除的内容

           <dependency>
                <groupId>org.apache.hadoop</groupId>
                <artifactId>hadoop-client</artifactId>
                <version>2.6.0</version>
                    <exclusions>
                    <exclusion>
                        <groupId>org.slf4j</groupId>
                        <artifactId>slf4j-log4j12</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>

  • 相关阅读:
    [bzoj3261]最大异或和(可持久化trie)
    [luogu3384] 【模板】树链剖分
    [luogu3369]普通平衡树(替罪羊树模板)
    fhq-treap模板
    [luogu3391] 【模板】文艺平衡树(fhq-treap反转区间)
    [luogu3369]普通平衡树(fhq-treap模板)
    [luogu3369]普通平衡树(treap模板)
    [bzoj3223]文艺平衡树(splay区间反转模板)
    A Path Plan(2018黑龙江省赛)
    Abandoned Animal(BAPC2017 Preliminaries )
  • 原文地址:https://www.cnblogs.com/oxspirt/p/8264833.html
Copyright © 2020-2023  润新知