programing

스프링 부트: 여러 SLF4J 바인딩

codeshow 2023. 4. 2. 11:40
반응형

스프링 부트: 여러 SLF4J 바인딩

이것은 아마 반복된 질문일 것입니다만, 저는 어디에 바인딩 충돌이 있는지 알 수 없습니다.나는 내 것이 있다.Spring Boot 1.2.6.RELEASE서비스를 실행하면 다음과 같은 오류가 나타납니다.

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/home/jscherman/.m2/repository/ch/qos/logback/logback-classic/1.1.3/logback-classic-1.1.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/jscherman/.m2/repository/org/slf4j/slf4j-log4j12/1.7.12/slf4j-log4j12-1.7.12.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [ch.qos.logback.classic.util.ContextSelectorStaticBinder]

이거는mvn dependency:tree산출량

[INFO] com.myenterprise:product-manager:jar:0.0.1-SNAPSHOT
[INFO] +- com.myenterprise.product:myproject-api:jar:0.0.1-SNAPSHOT:compile
[INFO] +- com.myenterprise.product:myproject-core:jar:0.0.1-SNAPSHOT:compile
[INFO] +- org.springframework.boot:spring-boot-starter-web:jar:1.2.6.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-tomcat:jar:1.2.6.RELEASE:compile
[INFO] |  |  +- org.apache.tomcat.embed:tomcat-embed-core:jar:8.0.26:compile
[INFO] |  |  +- org.apache.tomcat.embed:tomcat-embed-el:jar:8.0.26:compile
[INFO] |  |  +- org.apache.tomcat.embed:tomcat-embed-logging-juli:jar:8.0.26:compile
[INFO] |  |  \- org.apache.tomcat.embed:tomcat-embed-websocket:jar:8.0.26:compile
[INFO] |  +- com.fasterxml.jackson.core:jackson-databind:jar:2.4.6:compile
[INFO] |  |  +- com.fasterxml.jackson.core:jackson-annotations:jar:2.4.6:compile
[INFO] |  |  \- com.fasterxml.jackson.core:jackson-core:jar:2.4.6:compile
[INFO] |  +- org.hibernate:hibernate-validator:jar:5.1.3.Final:compile
[INFO] |  |  +- javax.validation:validation-api:jar:1.1.0.Final:compile
[INFO] |  |  +- org.jboss.logging:jboss-logging:jar:3.1.3.GA:compile
[INFO] |  |  \- com.fasterxml:classmate:jar:1.0.0:compile
[INFO] |  +- org.springframework:spring-core:jar:4.1.7.RELEASE:compile
[INFO] |  +- org.springframework:spring-web:jar:4.1.7.RELEASE:compile
[INFO] |  |  \- org.springframework:spring-aop:jar:4.1.7.RELEASE:compile
[INFO] |  \- org.springframework:spring-webmvc:jar:4.1.7.RELEASE:compile
[INFO] |     \- org.springframework:spring-expression:jar:4.1.7.RELEASE:compile
[INFO] +- org.springframework.boot:spring-boot-starter-data-jpa:jar:1.2.6.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-aop:jar:1.2.6.RELEASE:compile
[INFO] |  |  +- org.aspectj:aspectjrt:jar:1.8.6:compile
[INFO] |  |  \- org.aspectj:aspectjweaver:jar:1.8.6:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-jdbc:jar:1.2.6.RELEASE:compile
[INFO] |  |  +- org.springframework:spring-jdbc:jar:4.1.7.RELEASE:compile
[INFO] |  |  +- org.apache.tomcat:tomcat-jdbc:jar:8.0.26:compile
[INFO] |  |  |  \- org.apache.tomcat:tomcat-juli:jar:8.0.26:compile
[INFO] |  |  \- org.springframework:spring-tx:jar:4.1.7.RELEASE:compile
[INFO] |  +- org.hibernate:hibernate-entitymanager:jar:4.3.11.Final:compile
[INFO] |  |  +- org.jboss.logging:jboss-logging-annotations:jar:1.2.0.Beta1:compile
[INFO] |  |  +- org.hibernate:hibernate-core:jar:4.3.11.Final:compile
[INFO] |  |  |  +- antlr:antlr:jar:2.7.7:compile
[INFO] |  |  |  \- org.jboss:jandex:jar:1.1.0.Final:compile
[INFO] |  |  +- dom4j:dom4j:jar:1.6.1:compile
[INFO] |  |  |  \- xml-apis:xml-apis:jar:1.0.b2:compile
[INFO] |  |  +- org.hibernate.common:hibernate-commons-annotations:jar:4.0.5.Final:compile
[INFO] |  |  +- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:jar:1.0.0.Final:compile
[INFO] |  |  \- org.javassist:javassist:jar:3.18.1-GA:compile
[INFO] |  +- javax.transaction:javax.transaction-api:jar:1.2:compile
[INFO] |  +- org.springframework:spring-orm:jar:4.1.7.RELEASE:compile
[INFO] |  +- org.springframework.data:spring-data-jpa:jar:1.7.3.RELEASE:compile
[INFO] |  |  +- org.springframework.data:spring-data-commons:jar:1.9.3.RELEASE:compile
[INFO] |  |  \- org.slf4j:slf4j-api:jar:1.7.12:compile
[INFO] |  \- org.springframework:spring-aspects:jar:4.1.7.RELEASE:compile
[INFO] +- mysql:mysql-connector-java:jar:5.1.36:compile
[INFO] +- org.flywaydb:flyway-core:jar:3.1:compile
[INFO] +- org.springframework.security.oauth:spring-security-oauth2:jar:2.0.7.RELEASE:compile
[INFO] |  +- org.springframework:spring-beans:jar:4.1.7.RELEASE:compile
[INFO] |  +- org.springframework:spring-context:jar:4.1.7.RELEASE:compile
[INFO] |  +- org.springframework.security:spring-security-core:jar:3.2.8.RELEASE:compile
[INFO] |  |  \- aopalliance:aopalliance:jar:1.0:compile
[INFO] |  +- org.springframework.security:spring-security-config:jar:3.2.8.RELEASE:compile
[INFO] |  +- org.springframework.security:spring-security-web:jar:3.2.8.RELEASE:compile
[INFO] |  +- commons-codec:commons-codec:jar:1.6:compile
[INFO] |  \- org.codehaus.jackson:jackson-mapper-asl:jar:1.9.13:compile
[INFO] |     \- org.codehaus.jackson:jackson-core-asl:jar:1.9.13:compile
[INFO] +- org.springframework.boot:spring-boot-starter:jar:1.2.6.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot:jar:1.2.6.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-autoconfigure:jar:1.2.6.RELEASE:compile
[INFO] |  \- org.yaml:snakeyaml:jar:1.14:compile
[INFO] +- org.springframework.boot:spring-boot-starter-log4j:jar:1.2.6.RELEASE:compile
[INFO] |  +- org.slf4j:jcl-over-slf4j:jar:1.7.12:compile
[INFO] |  +- org.slf4j:jul-to-slf4j:jar:1.7.12:compile
[INFO] |  +- org.slf4j:slf4j-log4j12:jar:1.7.12:compile
[INFO] |  \- log4j:log4j:jar:1.2.17:compile
[INFO] \- org.springframework.boot:spring-boot-starter-test:jar:1.2.6.RELEASE:compile
[INFO]    +- junit:junit:jar:4.12:compile
[INFO]    +- org.mockito:mockito-core:jar:1.10.19:compile
[INFO]    |  \- org.objenesis:objenesis:jar:2.1:runtime
[INFO]    +- org.hamcrest:hamcrest-core:jar:1.3:compile
[INFO]    +- org.hamcrest:hamcrest-library:jar:1.3:compile
[INFO]    \- org.springframework:spring-test:jar:4.1.7.RELEASE:compile

그래서, 분명히 문제는logback아직 classpath에 있지만 출력에서 찾을 수 없어서 어디가 문제인지 모르겠어요.

오류를 발견할 수 있습니까?도와주시면 감사하겠습니다.


편집

이 문제가 발생하는 것은 서버를 Spring Boot Application으로 실행하는 경우뿐입니다.자바 어플리케이션으로 실행하면 오류가 사라집니다.좋은 생각 있어?

저도 똑같은 문제가 있어서 스프링 부츠에서 생기는 의존성밖에 알 수 없었습니다.또, log4j-over-slf4j도 도입되어 slf4j-log4j12의 제 요구와 모순됩니다.아래의 제외 항목을 추가하여 해결했습니다.이는 스프링 부트 로깅을 제외하는 것보다 구체적입니다.

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter</artifactId>
    <exclusions>
        <exclusion>
            <artifactId>logback-classic</artifactId>
            <groupId>ch.qos.logback</groupId>
        </exclusion>
        <exclusion>
            <artifactId>log4j-over-slf4j</artifactId>
            <groupId>org.slf4j</groupId>
        </exclusion>
    </exclusions>
</dependency>

지금까지의 회답은 모두 log4j2가 정상적으로 동작하지 않았기 때문에(적어도 저는 동작하지 않습니다), https://docs.spring.io/spring-boot/docs/current/reference/html/howto-logging.html#howto-configure-log4j-for-logging에서 솔루션을 찾았습니다.기본적으로는 제외합니다.org.springframework.boot:spring-boot-starter-logging부터org.springframework.boot:spring-boot-starter추가하다org.springframework.boot:spring-boot-starter-log4j2에 대한 의존으로서pom.xml.

로깅에 log4j를 사용하고 기본 로그백 구현을 제외하려면 이 종속성을 추가합니다(존속성이 없는 경우). 또는 exclusion 구를 추가합니다.

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

스프링 로깅 - 사용 방법을 참조하십시오.

종속성을 제거하다spring-boot-starter-log4j이 때문에,slf4j-log4j12사용하시는 것이 좋을 것 같습니다.log4j-over-slf4jlog4j에 의존하는 코드가 있는 경우.구별은 이쪽을 참조해 주세요.

클래스 패스에서 logback.xml을 사용하고 pom에서 spring-boot-starter-log4j:jar를 사용하는 것이 StaticLoggerBinder의 경합 원인입니다.

SLF4J: Found binding in [jar:file:/home/jscherman/.m2/repository/ch/qos/logback/logback-classic/1.1.3/logback-classic-1.1.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/jscherman/.m2/repository/org/slf4j/slf4j-log4j12/1.7.12/slf4j-log4j12-1.7.12.jar!/org/slf4j/impl/StaticLoggerBinder.class]

pom에서 로그 라이브러리(spring-boot-starter-log4j) 중 하나를 삭제하여 충돌을 제거합니다.

Maven Helper 플러그인은 의존관계 그래프를 빠르게 시각화하여 충돌을 식별하고 클릭 한 번으로 인라인으로 해결하는 데 매우 유용합니다.

이 오류는 클래스 경로에 여러 SLF4J 구현이 있기 때문에 발생합니다.SLF4J는 다양한 로깅 프레임워크(log4j 또는 logback 등)의 추상화입니다.SLF4J는 정적 메서드에 의해 컴파일 단계에서 구현을 검출합니다.

의존관계: tree, log4j만 검색되며 logback 관련 jar는 없습니다.

[INFO] +- org.springframework.boot:spring-boot-starter-log4j:jar:1.2.6.RELEASE:compile
[INFO] |  +- org.slf4j:jcl-over-slf4j:jar:1.7.12:compile
[INFO] |  +- org.slf4j:jul-to-slf4j:jar:1.7.12:compile
[INFO] |  +- org.slf4j:slf4j-log4j12:jar:1.7.12:compile
[INFO] |  \- log4j:log4j:jar:1.2.17:compile

maven - update project를 먼저 실행하고 다시 확인해야 합니다.

이 페이지의 위의 답변은 모두 정확하고 같은 방향을 가리키고 있지만 절차가 상당히 까다롭고 번거롭습니다.

표준 플러그인을 사용하거나 사용하는 것이 좋습니다.Maven 도우미 플러그인

앞으로 같은 문제에 직면할 사람이 또 있다면 이 글을 올립니다.

대규모 프로젝트에서는 여러 개의 종속성이 존재하며, 그 중 하나 또는 두 개에 제외를 적용하는 것이 항상 효과가 있는 것은 아닙니다.에는 역시 수 없었습니다.logback-classic내가 실행하려는 프로젝트의 종속성 트리에 있습니다.는 그 ★★★★★★★★★★★★★★★★★★★★★★★★★.

  • 빌드 경로에 포함된 다른 내부 프로젝트도 있었습니다.은 이이 the the 를 사용하고 있었다.logback-classic.

솔루션:

  • 번째 한지 아는 입니다. 즉, 프로젝트에 무엇이 필요한지 것입니다.logback-classic ★★★★★★★★★★★★★★★★★」slf4j-api
  • 하다', '제외하다', '제외하다'를 수 요.slf4j-api의존관계에 있습니다.
  • 에러가 하면, 「」를 해 주세요.slf4-api이며, .logback-classic의존관계 트리와 다른 내부 프로젝트에서 완전히 사라질 때까지요.
  • 않는 해 둘 필요가 .slf4j-api존존관관관관관관
  • 내부 프로젝트도 빌드 경로에 포함되어 있는 경우 해당 프로젝트에도 프로세스를 반복해야 할 수 있습니다.

언급URL : https://stackoverflow.com/questions/33071002/spring-boot-multiple-slf4j-bindings

반응형