【问题标题】:My application has application.yml in the resources folder however Spring boot application is complaining that application.properties is not found我的应用程序在资源文件夹中有 application.yml 但是 Spring boot 应用程序抱怨找不到 application.properties
【发布时间】:2021-07-08 03:50:34
【问题描述】:

我的应用程序在主资源和测试资源文件夹中有 application.yml,但是应用程序(带有 Maven 的 Spring boot 2.4)抱怨找不到 application.properties。

以下是错误。

2021-07-08 04:37:33.381 ERROR   --- [           main] o.s.test.context.TestContextManager      : Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@bd4ee01] to prepare test instance [com.test.SomeTests@6a7aa675]

java.lang.IllegalStateException: Failed to load ApplicationContext
        at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:132)
...
Caused by: java.io.FileNotFoundException: class path resource [application.properties] cannot be opened because it does not exist
        at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:187)

我试图在网上找到解决方案,但找不到。请帮忙。

【问题讨论】:

  • 听起来你有一个测试在某处明确指定application.properties,而不是使用引导基础设施。
  • 嗨@chrylis-cautiouslyoptimistic-感谢您的快速回复。你是对的。

标签: java spring spring-boot maven


【解决方案1】:

这对您的问题的描述不够充分,您将 application.yml 文件放在哪里?如果你在一个maven projet项目中,你应该把它放在src/main/resources文件夹下。

另外我不确定 spring 是否能够解释您文件的 .yml 文件扩展名,请尝试将其更改为 application.yaml

spring.io的注意事项

【讨论】:

    【解决方案2】:

    您可以通过使用 as 设置程序参数来明确指定您的应用程序属性位置:

    --spring.config.location=your_properties_path
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-12-26
      • 2017-01-09
      • 2018-07-06
      • 2023-02-10
      • 2018-05-07
      • 2020-10-12
      • 2022-08-21
      • 1970-01-01
      相关资源
      最近更新 更多