Application.properties 布尔定义值未在 bean 中使用

问题描述 投票:0回答:1

我有一个 bean 类,我想加载一个在 springboot 应用程序的 application.properties 文件中定义的布尔值。这是我的 application.properties 文件:

APP_CONTAINERIZED_VALUE=true

我的类被注释为@Component并像这样使用这个值:

@Value("${APP_CONTAINERIZED_VALUE:false}")
private boolean APP_CONTAINERIZED;

当我尝试运行 spring 服务器时,我收到此异常:

Caused by: Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'APP_CONTAINERIZED_VALUE' in value "${APP_CONTAINERIZED_VALUE}"

我做错了什么吗?我检查过其他类似的帖子,但似乎没有什么对我有用。

提前致谢

java spring spring-boot annotations
1个回答
0
投票

检查属性文件是否位于 Spring 支持的目录中。通常它是类路径的根。

这是可能位置的长列表

https://docs.spring.io/spring-boot/docs/1.2.3.RELEASE/reference/html/boot-features-external-config.html

如果您的属性文件位于 jar 包内,请验证它是否确实存在。有可能,您的 Maven 配置已损坏,文件被复制到错误的子文件夹中。

© www.soinside.com 2019 - 2024. All rights reserved.