250x250
Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
Tags
- MSSQL
- STS
- error
- Open Source
- maven
- Python
- spring
- AJAX
- ubuntu
- 설정
- oracle
- Eclipse
- 오픈소스
- JDBC
- Thymeleaf
- IntelliJ
- Source
- Core Java
- MySQL
- git
- 문서
- SpringBoot
- Spring Boot
- Docker
- Exception
- jpa
- myBatis
- Tomcat
- PostgreSQL
- JavaScript
Archives
- Today
- Total
헤르메스 LIFE
[Exception] SLF4J: Class path contains multiple SLF4J bindings 본문
728x90
개발환경
Spring Boot 2.2.4
JDK 1.8.0_202
REST + log4j2 설정 시 아래와 같은 오류가 발생했습니다.
SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/C:/Users/hermeswing/.m2/repository/ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/C:/Users/hermeswing/.m2/repository/org/apache/logging/log4j/log4j-slf4j-impl/2.12.1/log4j-slf4j-impl-2.12.1.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] DEBUG StatusLogger Using ShutdownCallbackRegistry class org.apache.logging.log4j.core.util.DefaultShutdownCallbackRegistry DEBUG StatusLogger org.slf4j.helpers.Log4jLoggerFactory is not on classpath. Good! WARN StatusLogger Multiple logging implementations found: Factory: org.apache.logging.log4j.core.impl.Log4jContextFactory, Weighting: 10 Factory: org.apache.logging.slf4j.SLF4JLoggerContextFactory, Weighting: 15 Using factory: org.apache.logging.slf4j.SLF4JLoggerContextFactory Logging system failed to initialize using configuration from 'classpath:log4j2.xml' java.lang.IllegalStateException: Logback configuration error detected: ERROR in ch.qos.logback.core.joran.spi.Interpreter@4:17 - no applicable action for [Properties], current ElementPath is [[Configuration][Properties]] |
DEBUG StatusLogger org.slf4j.helpers.Log4jLoggerFactory is not on classpath. Good! DEBUG StatusLogger Using ShutdownCallbackRegistry class org.apache.logging.log4j.core.util.DefaultShutdownCallbackRegistry WARN StatusLogger Multiple logging implementations found: Factory: org.apache.logging.log4j.core.impl.Log4jContextFactory, Weighting: 10 Factory: org.apache.logging.slf4j.SLF4JLoggerContextFactory, Weighting: 15 Using factory: org.apache.logging.slf4j.SLF4JLoggerContextFactory Exception in thread "main" java.lang.ExceptionInInitializerError at com.sample.Application.main(Application.java:17) Caused by: org.apache.logging.log4j.LoggingException: log4j-slf4j-impl cannot be present with log4j-to-slf4j at org.apache.logging.slf4j.Log4jLoggerFactory.validateContext(Log4jLoggerFactory.java:49) at org.apache.logging.slf4j.Log4jLoggerFactory.newLogger(Log4jLoggerFactory.java:39) at org.apache.logging.slf4j.Log4jLoggerFactory.newLogger(Log4jLoggerFactory.java:30) at org.apache.logging.log4j.spi.AbstractLoggerAdapter.getLogger(AbstractLoggerAdapter.java:54) at org.apache.logging.slf4j.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:30) at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:363) at org.apache.commons.logging.LogAdapter$Slf4jAdapter.createLocationAwareLog(LogAdapter.java:130) at org.apache.commons.logging.LogAdapter.createLog(LogAdapter.java:91) at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:67) at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:59) at org.springframework.boot.SpringApplication.(SpringApplication.java:196) ... 1 more |
pom.xml 파일에서 아래와 같이 추가만하면 된다고 합니다.... 만..
<!-- Log4j2 로깅 구현체를 사용을 위해 Spring Boot Starter에서 지원해주는 log4j2 의존성을 추가 해준다. -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
Spring Boot 는 기본적으로 logback 를 포함하고 있다고 합니다.
spring-boot-starter-logging 을 제외해 줘야 합니다.
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>SpringBootSample</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.4.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<!--
스프링 부트에서 Log4j2를 사용하기위해선 내부로깅에서 쓰이는 의존성을 제외해주어야 합니다.
기본적으로 Spring은 Slf4j라는 로깅 프레임워크를 사용합니다.
구현체를 손쉽게 교체할 수 있도록 도와주는 프레임 워크입니다.
Slf4j는 인터페이스고 내부 구현체로 logback을 가지고 있는데,
Log4j2를 사용하기 위해 exclude 해야 합니다.
-->
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- Log4j2 로깅 구현체를 사용을 위해 Spring Boot Starter에서 지원해주는 log4j2 의존성을 추가 해준다. -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
<!-- 빌드 플러그인 -->
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
gradle 를 사용하는 경우 참조 huisam.tistory.com/entry/log4j2
참조 : hermeslog.tistory.com/448?category=302344
참조 : hermeslog.tistory.com/449
728x90