簡體   English   中英

在Spring Boot中找到多種日志記錄實現

[英]Multiple logging implementations found in Spring Boot

每當我運行它時,我就有多模塊的maven項目,出現以下錯誤:

Exception in thread "main" java.lang.IllegalArgumentException: LoggerFactory is not a Logback LoggerContext but Logback is on the classpath. Either remove Logback or the competing implementation

我嘗試了幾種不同的方法將其刪除,但沒有任何效果。 例如:

1) 解決Maven項目中的多個SLF4J綁定

2) Spring Boot:多個SLF4J綁定

3) https://dzone.com/articles/solving-dependency-conflicts-in-maven

但是以上解決方案均不適合我。

這是模塊的pom.xml:

<dependencies>
        <dependency>
            <groupId>com.mydomain</groupId>
            <artifactId>commons-module</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>

        <dependency>
            <groupId>org.littleshoot</groupId>
            <artifactId>proxy</artifactId>
            <version>1.0</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-cache</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.5.5</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

這是模塊的依賴關系樹:

 com.mydomain:circuit-module:jar:1.0-SNAPSHOT
[INFO] +- com.mydomain:commons-module:jar:1.0-SNAPSHOT:compile
[INFO] |  +- javax.validation:validation-api:jar:2.0.1.Final:compile
[INFO] |  +- org.postgresql:postgresql:jar:42.2.1:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-data-jpa:jar:2.0.0.RELEASE:compile
[INFO] |  |  +- org.springframework.boot:spring-boot-starter-aop:jar:2.0.0.RELEASE:compile
[INFO] |  |  |  \- org.aspectj:aspectjweaver:jar:1.8.13:compile
[INFO] |  |  +- org.springframework.boot:spring-boot-starter-jdbc:jar:2.0.0.RELEASE:compile
[INFO] |  |  |  +- com.zaxxer:HikariCP:jar:2.7.8:compile
[INFO] |  |  |  \- org.springframework:spring-jdbc:jar:5.0.4.RELEASE:compile
[INFO] |  |  +- org.hibernate:hibernate-core:jar:5.2.14.Final:compile
[INFO] |  |  |  +- org.jboss.logging:jboss-logging:jar:3.3.2.Final:compile
[INFO] |  |  |  +- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:jar:1.0.0.Final:compile
[INFO] |  |  |  +- org.javassist:javassist:jar:3.22.0-GA:compile
[INFO] |  |  |  +- antlr:antlr:jar:2.7.7:compile
[INFO] |  |  |  +- org.jboss:jandex:jar:2.0.3.Final:compile
[INFO] |  |  |  +- com.fasterxml:classmate:jar:1.3.4:compile
[INFO] |  |  |  +- dom4j:dom4j:jar:1.6.1:compile
[INFO] |  |  |  \- org.hibernate.common:hibernate-commons-annotations:jar:5.0.1.Final:compile
[INFO] |  |  +- javax.transaction:javax.transaction-api:jar:1.2:compile
[INFO] |  |  +- org.springframework.data:spring-data-jpa:jar:2.0.5.RELEASE:compile
[INFO] |  |  |  +- org.springframework.data:spring-data-commons:jar:2.0.5.RELEASE:compile
[INFO] |  |  |  +- org.springframework:spring-orm:jar:5.0.4.RELEASE:compile
[INFO] |  |  |  \- org.springframework:spring-tx:jar:5.0.4.RELEASE:compile
[INFO] |  |  \- org.springframework:spring-aspects:jar:5.0.4.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-mail:jar:2.0.0.RELEASE:compile
[INFO] |  |  \- com.sun.mail:javax.mail:jar:1.6.1:compile
[INFO] |  |     \- javax.activation:activation:jar:1.1:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-freemarker:jar:2.0.0.RELEASE:compile
[INFO] |  |  \- org.freemarker:freemarker:jar:2.3.27-incubating:compile
[INFO] |  +- commons-validator:commons-validator:jar:1.6:compile
[INFO] |  |  +- commons-beanutils:commons-beanutils:jar:1.9.2:compile
[INFO] |  |  +- commons-digester:commons-digester:jar:1.8.1:compile
[INFO] |  |  +- commons-logging:commons-logging:jar:1.2:compile
[INFO] |  |  \- commons-collections:commons-collections:jar:3.2.2:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-amqp:jar:2.0.0.RELEASE:compile
[INFO] |  |  +- org.springframework:spring-messaging:jar:5.0.4.RELEASE:compile
[INFO] |  |  \- org.springframework.amqp:spring-rabbit:jar:2.0.2.RELEASE:compile
[INFO] |  |     +- org.springframework.amqp:spring-amqp:jar:2.0.2.RELEASE:compile
[INFO] |  |     +- com.rabbitmq:amqp-client:jar:5.1.2:compile
[INFO] |  |     +- com.rabbitmq:http-client:jar:1.3.1.RELEASE:compile
[INFO] |  |     +- org.springframework:spring-web:jar:5.0.4.RELEASE:compile
[INFO] |  |     \- org.springframework.retry:spring-retry:jar:1.2.2.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-data-redis:jar:2.0.0.RELEASE:compile
[INFO] |  |  \- org.springframework.data:spring-data-redis:jar:2.0.5.RELEASE:compile
[INFO] |  |     +- org.springframework.data:spring-data-keyvalue:jar:2.0.5.RELEASE:compile
[INFO] |  |     \- org.springframework:spring-oxm:jar:5.0.4.RELEASE:compile
[INFO] |  \- redis.clients:jedis:jar:2.9.0:compile
[INFO] |     \- org.apache.commons:commons-pool2:jar:2.5.0:compile
[INFO] +- org.littleshoot:proxy:jar:1.0:compile
[INFO] +- org.springframework.boot:spring-boot-starter-cache:jar:2.0.0.RELEASE:compile
[INFO] |  +- org.springframework:spring-context:jar:5.0.4.RELEASE:compile
[INFO] |  |  +- org.springframework:spring-aop:jar:5.0.4.RELEASE:compile
[INFO] |  |  +- org.springframework:spring-beans:jar:5.0.4.RELEASE:compile
[INFO] |  |  \- org.springframework:spring-expression:jar:5.0.4.RELEASE:compile
[INFO] |  \- org.springframework:spring-context-support:jar:5.0.4.RELEASE:compile
[INFO] +- org.springframework.boot:spring-boot-starter-test:jar:2.0.0.RELEASE:test
[INFO] |  +- org.springframework.boot:spring-boot-test:jar:2.0.0.RELEASE:test
[INFO] |  +- org.springframework.boot:spring-boot-test-autoconfigure:jar:2.0.0.RELEASE:test
[INFO] |  +- com.jayway.jsonpath:json-path:jar:2.4.0:test
[INFO] |  |  +- net.minidev:json-smart:jar:2.3:test
[INFO] |  |  |  \- net.minidev:accessors-smart:jar:1.2:test
[INFO] |  |  |     \- org.ow2.asm:asm:jar:5.0.4:test
[INFO] |  |  \- org.slf4j:slf4j-api:jar:1.7.25:compile
[INFO] |  +- junit:junit:jar:4.12:test
[INFO] |  +- org.assertj:assertj-core:jar:3.9.1:test
[INFO] |  +- org.mockito:mockito-core:jar:2.15.0:test
[INFO] |  |  +- net.bytebuddy:byte-buddy:jar:1.7.10:test
[INFO] |  |  +- net.bytebuddy:byte-buddy-agent:jar:1.7.10:test
[INFO] |  |  \- org.objenesis:objenesis:jar:2.6:test
[INFO] |  +- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO] |  +- org.hamcrest:hamcrest-library:jar:1.3:test
[INFO] |  +- org.skyscreamer:jsonassert:jar:1.5.0:test
[INFO] |  |  \- com.vaadin.external.google:android-json:jar:0.0.20131108.vaadin1:test
[INFO] |  +- org.springframework:spring-core:jar:5.0.4.RELEASE:compile
[INFO] |  |  \- org.springframework:spring-jcl:jar:5.0.4.RELEASE:compile
[INFO] |  +- org.springframework:spring-test:jar:5.0.4.RELEASE:test
[INFO] |  \- org.xmlunit:xmlunit-core:jar:2.5.1:test
[INFO] +- org.apache.httpcomponents:httpclient:jar:4.5.5:test
[INFO] |  +- org.apache.httpcomponents:httpcore:jar:4.4.9:test
[INFO] |  \- commons-codec:commons-codec:jar:1.11:test
[INFO] +- com.fasterxml.jackson.core:jackson-databind:jar:2.9.4:test
[INFO] |  +- com.fasterxml.jackson.core:jackson-annotations:jar:2.9.0:test
[INFO] |  \- com.fasterxml.jackson.core:jackson-core:jar:2.9.4:test
[INFO] +- org.springframework.boot:spring-boot-starter:jar:2.0.0.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot:jar:2.0.0.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-autoconfigure:jar:2.0.0.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-logging:jar:2.0.0.RELEASE:compile
[INFO] |  |  +- ch.qos.logback:logback-classic:jar:1.2.3:compile
[INFO] |  |  |  \- ch.qos.logback:logback-core:jar:1.2.3:compile
[INFO] |  |  +- org.apache.logging.log4j:log4j-to-slf4j:jar:2.10.0:compile
[INFO] |  |  |  \- org.apache.logging.log4j:log4j-api:jar:2.10.0:compile
[INFO] |  |  \- org.slf4j:jul-to-slf4j:jar:1.7.25:compile
[INFO] |  +- javax.annotation:javax.annotation-api:jar:1.3.2:compile
[INFO] |  \- org.yaml:snakeyaml:jar:1.19:runtime
[INFO] +- commons-lang:commons-lang:jar:2.6:compile
[INFO] \- org.projectlombok:lombok:jar:1.16.20:provided

我應該在哪里將標記與要排除的模塊放在一起,以便它起作用?

您可能想要從引導啟動程序中排除日志記錄,但是隨后您可能需要為特定的日志記錄框架添加依賴項。

<dependency>
    <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
        <!-- Exclude Spring Boot logging -->
        <exclusions>
            <exclusion>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-logging</artifactId>
            </exclusion>
        </exclusions>
</dependency>

以類似的方式從spring-boot-starter-logging中排除或排除Logback

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM