SprinBoot 프로젝트 시작 오류 Exception in thread "main"java.lang.reflect.InvocationTargetException
8794 단어 기타
lottery-api-start........
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/data/javaprogram/lottery_api/lottery_api.war!/WEB-INF/lib/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/data/javaprogram/lottery_api/lottery_api.war!/WEB-INF/lib/logback-classic-1.2.3.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 [org.slf4j.impl.Log4jLoggerFactory]
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
at org.springframework.boot.loader.WarLauncher.main(WarLauncher.java:58)
Caused by: 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 loaded from jar:file:/data/javaprogram/lottery_api/lottery_api.war!/WEB-INF/lib/slf4j-log4j12-1.7.25.jar!/). If you are using WebLogic you will need to add 'org.slf4j' to prefer-application-packages in WEB-INF/weblogic.xml: org.slf4j.impl.Log4jLoggerFactory
at org.springframework.util.Assert.instanceCheckFailed(Assert.java:637)
at org.springframework.util.Assert.isInstanceOf(Assert.java:537)
at org.springframework.boot.logging.logback.LogbackLoggingSystem.getLoggerContext(LogbackLoggingSystem.java:274)
at org.springframework.boot.logging.logback.LogbackLoggingSystem.beforeInitialize(LogbackLoggingSystem.java:99)
at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationStartingEvent(LoggingApplicationListener.java:191)
at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:170)
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127)
at org.springframework.boot.context.event.EventPublishingRunListener.starting(EventPublishingRunListener.java:68)
at org.springframework.boot.SpringApplicationRunListeners.starting(SpringApplicationRunListeners.java:48)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:313)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1255)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1243)
at com.zhibo.api.App.main(App.java:10)
... 8 more
까닭
대충 봐도 짐작이 간다. 하나, 둘, 클래스 경로에서Found binding SLF4J 로그 인터페이스를 2번 사용한다.공식 로그 문서:
SLF4J API is designed to bind with one and only one underlying logging framework at a time. If more than one binding is present on the class path, SLF4J will emit a warning, listing the location of those bindings.
When multiple bindings are available on the class path, select one and only one binding you wish to use, and remove the other bindings. For example, if you have both slf4j-simple-1.8.0-beta4.jar and slf4j-nop-1.8.0-beta4.jar on the class path and you wish to use the nop (no-operation) binding, then remove slf4j-simple-1.8.0-beta4.jar from the class path.
The list of locations that SLF4J provides in this warning usually provides sufficient information to identify the dependency transitively pulling in an unwanted SLF4J binding into your project. In your project's pom.xml file, exclude this SLF4J binding when declaring the unscrupulous dependency. For example, cassandra-all version 0.8.1 declares both log4j and slf4j-log4j12 as compile-time dependencies. Thus, when you include cassandra-all as a dependency in your project, the cassandra-all declaration will cause both slf4j-log4j12.jar and log4j.jar to be pulled in as dependencies. In case you do not wish to use log4j as the the SLF4J backend, you can instruct Maven to exclude these two artifacts as shown next:
org.apache.cassandra
cassandra-all
0.8.1
org.slf4j
slf4j-log4j12
log4j
log4j
NOTE The warning emitted by SLF4J is just that, a warning. Even when multiple bindings are present, SLF4J will pick one logging framework/implementation and bind with it. The way SLF4J picks a binding is determined by the JVM and for all practical purposes should be considered random. As of version 1.6.6, SLF4J will name the framework/implementation class it is actually bound to.
Embedded components such as libraries or frameworks should not declare a dependency on any SLF4J binding but only depend on slf4j-api. When a library declares a compile-time dependency on a SLF4J binding, it imposes that binding on the end-user, thus negating SLF4J's purpose. When you come across an embedded component declaring a compile-time dependency on any SLF4J binding, please take the time to contact the authors of said component/library and kindly ask them to mend their ways.
인용 의존을 주지만 외부jar와springboot 자체의 slf4j 충돌을 인용합니다. 이 의존은 제 문제를 해결할 수 없습니다.
그래서 마지막으로jar이나springboot 자체의 slf4j를 제거하면 해결할 수 있습니다.
jar는 패키지를 다시 컴파일해야 합니다. 번거로우며 sb 자체의 slf4j를 과감하게 제거합니다.나만의 솔루션:
제 프로젝트에 공공 응용 프로그램 JAR 패키지가 있기 때문에 JAR에서 org를 인용했습니다.slf4j, 그래서 저는 SpringBoot 자체가 가지고 있는'org.slf4j 배제.
org.springframework.boot
spring-boot-starter-web
org.slf4j
slf4j-log4j12
인터넷에서 찾은 해결 방법:
해결 방법 1:
starter-web 시작 의존에서 slf4j 제거
org.springframework.boot
spring-boot-starter-web
ch.qos.logback
logback-classic
해결 방법 2:
org.springframework.boot
spring-boot-configuration-processor
true
시작은jar의 기본 로그 단계로 시작합니다.
그리고 성공적으로 시작합니다!
SLF4J 문서:http://www.slf4j.org/codes.html#multiple_bindings
springboot 자체 로그logback 로그를 제거하고 외부jar에 부어 동기화하는 로그 로그로 수정하는 것을 권장합니다
해결 방법 3:
org.springframework.boot
spring-boot-starter-log4j
1.3.8.RELEASE
org.slf4j
slf4j-log4j12
해결 방법 4:
org.apache.logging.log4j
log4j-slf4j-impl
저자: 아주머니의 케첩https://blog.csdn.net/weixin_38361347/article/details/88351246판권 성명: 본고는 블로거의 오리지널 문장입니다. 옮겨 싣기 위해 블로거 링크를 첨부하세요!
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
요구사항 정의요구사항 정의 작성 방법 개요 ・목적 표시되고 있는 텍스트를 가변으로 한다 · 과제 표시된 텍스트가 변경되지 않음 ・해결 표시되고 있는 텍스트가 가변이 된다 사양 · 표시 정의 각 편집 화면 ○○ 표시되고 있는 텍스...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.