스프링 부트 서버를 시작할 수 없습니다.
스프링 부트는 처음이라 서버를 시작하려고 하면 다음과 같은 예외가 나타납니다.이것이 의존관계 갈등과 관련이 있다는 것은 이해하지만, 여전히 이해할 수 없습니다.나는 의존관계를 관리하기 위해 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
(class org.slf4j.impl.Log4jLoggerFactory) Object of class
[org.slf4j.impl.Log4jLoggerFactory] must be an instance of class
ch.qos.logback.classic.LoggerContext at
org.springframework.util.Assert.isInstanceOf(Assert.java:339) at
org.springframework.boot.logging.logback.LogbackLoggingSystem.initialize(LogbackLoggingSystem.java:93)
at
org.springframework.boot.logging.AbstractLoggingSystem.initializeWithSensibleDefaults(AbstractLoggingSystem.java:62)
at
org.springframework.boot.logging.AbstractLoggingSystem.beforeInitialize(AbstractLoggingSystem.java:45)
at
org.springframework.boot.logging.logback.LogbackLoggingSystem.beforeInitialize(LogbackLoggingSystem.java:69)
at
org.springframework.boot.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:135)
at
org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:98)
at
org.springframework.boot.context.event.EventPublishingRunListener.publishEvent(EventPublishingRunListener.java:100)
at
org.springframework.boot.context.event.EventPublishingRunListener.started(EventPublishingRunListener.java:54)
at
org.springframework.boot.SpringApplication.run(SpringApplication.java:276)
at
org.springframework.boot.SpringApplication.run(SpringApplication.java:952)
at
org.springframework.boot.SpringApplication.run(SpringApplication.java:941)
at org.magnum.mobilecloud.video.Application.main(Application.java:30)
해결 완료:다음 항목을 POM.xml에 추가합니다.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j</artifactId>
</dependency>
spring-boot-starter-web 및 spring-boot-starter-actuator에서 logback-classic 제외
compile("org.springframework.boot:spring-boot-starter-web:1.1.10.RELEASE") {
exclude module: "spring-boot-starter-tomcat"
exclude module: "spring-boot-starter-logging"
exclude module: "logback-classic"
}
compile("org.springframework.boot:spring-boot-starter-actuator:1.1.10.RELEASE") {
exclude module: "logback-classic"
}
이를 build.gradle에 추가합니다.
configurations.all {
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-tomcat'
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
exclude group: 'org.springframework.boot', module: 'logback-classic'
}
제 프로젝트에서는
- 스프링 부트 1.4.2풀어주다
- slf4j 1.7.21과 logback 1.1.7의 양쪽입니다(모듈A라고 불리는 일부 의존관계는 logback 1.1.2에 의존하며 이것이 문제입니다.
종속성 중재 - 아티팩트의 여러 버전이 발견될 때 사용할 종속성 버전을 결정합니다.현재 Maven 2.0은 "가장 가까운 정의"만 지원합니다. 즉, 종속성 트리에서 프로젝트에 가장 가까운 종속성 버전을 사용합니다.프로젝트의 POM에 명시적으로 선언함으로써 언제든지 버전을 보증할 수 있습니다.두 개의 종속성 버전이 종속성 트리에서 동일한 깊이에 있는 경우, Maven 2.0.8까지는 어떤 버전이 이길지 정의되지 않았지만, Maven 2.0.9 이후로는 첫 번째 선언이 이깁니다."가장 가까운 정의"는 사용되는 버전이 의존관계 트리에서 프로젝트에 가장 가까운 버전을 의미합니다.예를 들어 A, B, C의 의존관계가 A -> B -> C -> D 2.0 및 A -> E -> D 1.0으로 정의되어 있는 경우 D 1.0은 A에서D까지의 경로를 구축하기 위해 사용됩니다.A에서 D 2.0에 종속성을 명시적으로 추가하여 D 2.0을 강제로 사용할 수 있습니다.
그래서 maven은 내 프로젝트에서 logback 1.1.7을 사용합니다.모듈 A가 1.1.7과 호환되지 않거나 로그백 1.1.7이 slf4j 1.7.21과 호환되지 않는지 모르겠습니다.폼에 의존관리가 추가되어 있습니다.maven에게 lockback 1.1.2만 사용하라고 합니다.문제는 해결됐습니다.
<dependencyManagement>
<dependencies>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.2</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.1.2</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-access</artifactId>
<version>1.1.2</version>
</dependency>
</dependencies>
</dependencyManagement>
다음과 같은 구성을 제공합니다.빌드 파일을 사용할 수 있었습니다.
configurations {
all*.exclude group: "org.springframework.boot", module: "spring-boot-starter-logging"
all*.exclude group: "ch.qos.logback"
all*.exclude group: "org.slf4j", module: "log4j-over-slf4j" // allow using log4j 2.x
all*.exclude group: "org.slf4j", module: "slf4j-simple" // log4j is the configured backend
}
답변을 반복하지만 Eclipse를 사용하여 spring-boot-starter-logging 종속성을 제외할 수 있습니다.
- 종속 계층 선택
- 오른쪽 상단 로깅 검색
- spring-boot-starter-logging 선택
- 마우스 오른쪽 버튼 매븐 아티팩트 제외
gradle 솔루션은 build.gradle에 다음 행을 추가하고 있습니다.
configurations {
all*.exclude module : 'spring-boot-starter-logging'
}
Logback이 포함된 종속성을 모두 제거할 것을 권장합니다.가장 일반적인 것은 다음과 같습니다.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
그것은 나에게 효과가 있었다.
Spring Boot에서는 Log4j 2가 클래스 패스에 있는 경우 로깅 설정에 사용할 수 있습니다.종속성 어셈블리에 시작 프로그램을 사용하는 경우 로그백을 제외하고 대신 log4j 2를 포함해야 합니다.
다음 의존관계를 이 순서로 추가하여 문제를 해결했습니다.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
최종적으로 로그백 의존관계를 배제하고 log4j 의존관계를 명시적으로 추가하여 이 문제를 해결했습니다.
언급URL : https://stackoverflow.com/questions/26061860/unable-to-start-spring-boot-server
'sourcecode' 카테고리의 다른 글
Springfox swagger-ui.html이 기본 URL을 추론할 수 없음 - 쿠키 누락으로 인해 발생함 (0) | 2023.02.23 |
---|---|
AngularJS + 돛.js (0) | 2023.02.23 |
인코딩된 암호가 BCrypt와 같지 않습니다. (0) | 2023.02.23 |
utf-8의 python jsonify 사전 (0) | 2023.02.23 |
경고 .ts 파일을 삭제하는 방법은 TypeScript 컴파일의 일부이지만 사용되지 않습니다. (0) | 2023.02.18 |