当前位置: 首页 > 知识库问答 >
问题:

Spring Boot无法选择log4j2依赖项

闻人浩波
2023-03-14

找不到类似的问题,所以提出这个问题。抱歉,如果重复。

试图在spring boot(1.5.9版)应用程序中使用log4j2-

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <exclusions>
        <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-log4j2</artifactId>
</dependency>

但不知怎的,spring boot仍然在寻找logback依赖(mvn依赖树中处处排除logback依赖)-

Exception in thread "main" java.lang.NoClassDefFoundError: ch/qos/logback/classic/turbo/TurboFilter
    at java.lang.Class.getDeclaredConstructors0(Native Method)
    at java.lang.Class.privateGetDeclaredConstructors(Class.java:2671)
    at java.lang.Class.getConstructor0(Class.java:3075)
    at java.lang.Class.getConstructor(Class.java:1825)
    at org.springframework.boot.logging.LoggingSystem.get(LoggingSystem.java:169)
    at org.springframework.boot.logging.LoggingSystem.get(LoggingSystem.java:160)
    at org.springframework.boot.logging.LoggingApplicationListener.onApplicationStartingEvent(LoggingApplicationListener.java:229)
    at org.springframework.boot.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:209)
    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:122)
    at org.springframework.boot.context.event.EventPublishingRunListener.starting(EventPublishingRunListener.java:69)
    at org.springframework.boot.SpringApplicationRunListeners.starting(SpringApplicationRunListeners.java:48)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:292)
    at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:134)
    at Test.main(Test.java:30)
Caused by: java.lang.ClassNotFoundException: ch.qos.logback.classic.turbo.TurboFilter
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 17 more

共有1个答案

齐元章
2023-03-14

似乎缺少Log4j2配置文件。在资源中添加配置文件,这可能会解决问题。

 类似资料:
  • 在我们的项目中,我们使用具有依赖项的库,例如: 作为安全修复的一部分,我们假设使用更高版本的依赖项。通用编解码器:通用编解码器:1.14。在不升级expo-file-system的情况下,有没有办法告诉gradle/maven我们要用一个特定版本的commons-codec:commons-codec?

  • Yarn supports selective version resolutions, which lets you define custom package versions inside your dependencies through the resolutions field in your package.json file. Normally, this would requir

  • 我有一个Maven项目,我想使用log4j2和slf4j。所以我添加了这个依赖项: 就我所知,它似乎起作用了。但我的问题是关于log4j-slf4j-impl的可传递依赖关系。 为什么IntelliJ显示log4j-core引入了log4j-api,但由于是重复的,所以忽略了它(我相信下面的截图是这么说的)?我该如何预防呢?

  • 问题内容: 当我输入command go build时,我有一个项目具有来自bitbucket上私人存储库的多个依赖项。我得到这个错误 无法识别的导入路径“ bitbucket.xxx.xx / xx / x” x509:证书由未知授权机构签名 我已经尝试了几种方法,例如添加令牌 git config –global http.extraheader令牌 配置为ssh git config –gl

  • 我是一名新的Android学习者,我正在为语言翻译制作我的第一个Android应用程序。在添加了一些依赖项之后,我遇到了一些问题。我该怎么解决这个问题? Gradle同步失败:无法解决配置的所有依赖项: app: dedegRuntimeClasspath。无法确定android.arch.lifecycle的工件: livedata: 1.1.1:脱机模式下没有缓存版本有关详细信息,请参阅IDE

  • 我有一个控制器 服务接口 我想在我的控制器中使用@autowired来使用该服务,但当我运行应用程序时,我得到以下错误 org.springframework.beans.factory.beanCreationException:创建名为“demo application”的bean时出错:注入autowired依赖项失败;嵌套异常为org.SpringFramework.Beans.Facto