我引入了spring-boot-starter-web,使用了它自己的spring-boot-starter-logging框架,在yaml中指定了配置文件,并报告了启动错误yaml:
logging:
level:
root: info
com.felix.flink.tutorial.api: debug
config: classpath:logback-spring.xml
梅文:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.felix</groupId>
<artifactId>flink-tutorial-component</artifactId>
<version>${revision}</version>
</dependency>
</dependencies>
例外情况:
23:45:33.009 [Thread-0] DEBUG org.springframework.boot.devtools.restart.classloader.RestartClassLoader - Created RestartClassLoader org.springframework.boot.devtools.restart.classloader.RestartClassLoader@7abaedae
Exception in thread "restartedMain" java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)
Caused by: java.lang.NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder
at org.springframework.boot.logging.logback.LogbackLoggingSystem.getLoggerContext(LogbackLoggingSystem.java:293)
at org.springframework.boot.logging.logback.LogbackLoggingSystem.beforeInitialize(LogbackLoggingSystem.java:118)
at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationStartingEvent(LoggingApplicationListener.java:238)
at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:220)
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:176)
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:169)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:143)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:131)
at org.springframework.boot.context.event.EventPublishingRunListener.starting(EventPublishingRunListener.java:79)
at org.springframework.boot.SpringApplicationRunListeners.lambda$starting$0(SpringApplicationRunListeners.java:56)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1540)
at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:120)
at org.springframework.boot.SpringApplicationRunListeners.starting(SpringApplicationRunListeners.java:56)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:299)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1295)
at com.felix.flink.tutorial.api.FlinkTutorialApiApplication.main(FlinkTutorialApiApplication.java:15)
... 5 more
Caused by: java.lang.ClassNotFoundException: org.slf4j.impl.StaticLoggerBinder
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 22 more
Process finished with exit code 0
我已经导入slf 4j 2.0.3直接在pom,但它不工作
1条答案
按热度按时间bxpogfeg1#
SLF 4J在1.x和2.x版本之间彻底改变了它的实现方式。在1.x中,绑定类需要提供一个名为
org.slf4j.impl.StaticLoggerBinder
的类--这个类是缺失的。在2.x中,它使用ServiceLoader
机制。Sping Boot 目前仍然使用SLF 4J 1.7.36,通过
spring-boot-starter-web
-〉spring-boot-starter
-〉spring-boot-starter-logging
。后者依赖于一些SLF 4J桥,以及logback-classic
,后者反过来依赖于SLF 4J 1.7.32。我认为1.7.36“赢”了1.7.32。除非您的其他依赖项中有一个对SLF 4J 2.x的可传递依赖项,否则一切都应该正常工作。如果您这样做了,那么您将混合使用SLF 4J 1.x和2.x,这根本行不通。将2.x依赖项替换为1.x依赖项,您应该可以正常工作(除非您使用2.x中添加的fluent API)。