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

标签 java spring-boot maven configuration java-11

我在将应用程序迁移到 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/

相关文章:

java - Mockito 如何测试 findById() 返回一个 Optional

java - Java中的时间测量开销

java - ViewPager nullPointerException 错误

java - 从构造函数调用 jframe 方法

java - Spring Data Elastic Search 与 Java 高级 REST 客户端

java - log4j2 java.lang.NoClassDefFoundError : org/apache/logging/log4j/LogManager 错误

java - 在项目上执行 sonarQube 的问题由 : java. lang.UnsupportedClassVersionError: org/sonarsource/scanner/maven/SonarQubeMojo 引起

java - Java中的无界通配符

java - 使用 PostgreSQL 和 Spring Boot 时是否有规则禁止将其实体类命名为 "User"?

java - 如何链接 react 堆订户