gpt4 book ai didi

java - 无法使用 java 11 在 Spring Boot 中加载日志记录资源文件

转载 作者:行者123 更新时间:2023-12-01 19:44:47 26 4
gpt4 key购买 nike

我在将应用程序迁移到 java 11 时遇到问题。我在尝试加载日志配置时收到 FileNotFoundException

java.io.FileNotFoundException: class path resource [logging/logback-local.xml] cannot be resolved to URL because it does not exist
at spring.core@5.2.1.RELEASE/org.springframework.util.ResourceUtils.getURL(ResourceUtils.java:137)
at spring.boot@2.1.10.RELEASE/org.springframework.boot.context.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:293)
at spring.boot@2.1.10.RELEASE/org.springframework.boot.context.logging.LoggingApplicationListener.initialize(LoggingApplicationListener.java:264)
at spring.boot@2.1.10.RELEASE/org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEnvironmentPreparedEvent(LoggingApplicationListener.java:226)
at spring.boot@2.1.10.RELEASE/org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:203)
at spring.context@5.2.1.RELEASE/org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
at spring.context@5.2.1.RELEASE/org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
at spring.context@5.2.1.RELEASE/org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
at spring.context@5.2.1.RELEASE/org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127)
at spring.boot@2.1.10.RELEASE/org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:76)
at spring.boot@2.1.10.RELEASE/org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:53)
at spring.boot@2.1.10.RELEASE/org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:342)
at spring.boot@2.1.10.RELEASE/org.springframework.boot.SpringApplication.run(SpringApplication.java:305)
at spring.boot@2.1.10.RELEASE/org.springframework.boot.SpringApplication.run(SpringApplication.java:1215)
at spring.boot@2.1.10.RELEASE/org.springframework.boot.SpringApplication.run(SpringApplication.java:1204)
at FooApplicationModule@0.0.1-SNAPSHOT/foo.bar.Application.main(Application.java:23)

这是通过配置完成的,并在 Java 8 中工作:

这是我的应用程序.yml

logging:
config: classpath:logging/logback-local.xml

应用程序结构如下所示:

src
-main
-java
-foo.bar.Application.java
-resources
-application.yml
-logging
-logback-local.xml
pom.xml

pom:

<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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.10.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>foo.group</groupId>
<artifactId>application</artifactId>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

<java.version>11</java.version>
<spring.version>5.2.1.RELEASE</spring.version>
<spring.boot.version>2.1.10.RELEASE</spring.boot.version>
</properties>

<dependencies>
...
</dependencies>

<build>
<finalName>${project.artifactId}</finalName>
<sourceDirectory>${project.basedir}/src/main/java</sourceDirectory>
<resources>
<resource>
<directory>${project.basedir}/src/main/resources</directory>
</resource>
</resources>
<testSourceDirectory>${project.basedir}/src/test/java</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<annotationProcessorPaths>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${mapstruct.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>

</project>

我认为这是拼图模块化系统的问题,但我在互联网上找不到任何解决方案。

感谢您的帮助!

最佳答案

所以经过一些摆弄,使用哈蒂斯的建议,问题消失了。我不知道是什么原因导致了这个问题。

关于java - 无法使用 java 11 在 Spring Boot 中加载日志记录资源文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59136781/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com