java - Spring Boot 中的外部 YAML 属性文件和普通属性文件

标签 java spring spring-mvc spring-boot properties

这就是我设置外部配置文件的方式:

/** for .yaml file
@Configuration
@PropertySource("classpath:waterlvl.yaml")
@ConfigurationProperties("Alerts")
public class WaterLvlAlertConfig {

/** for .properties file
@Component
@PropertySource("classpath:waterlvl.properties")
public class WaterLvlConfig {

未选取属性,并且我的文件位于资源文件内。我认为我提供的路径是错误的。我做错了什么?

最佳答案

在 spring boot 中,使用 .yaml 配置时不能使用 @PropertySource。请参阅第 24.6.4 点外部化配置文档中的 YAML 缺点。另外,之前回答了类似的问题,请参阅-Spring boot external configuration of property file

关于java - Spring Boot 中的外部 YAML 属性文件和普通属性文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45754308/

相关文章:

java - 在 android 上移植屏幕截图 java 应用程序

java - 我应该使用 AbstractAnnotationConfigDispatcherServletInitializer 还是 WebApplicationInitializer 配置 Spring 4.0 mvc + Security 应用程序?

java - 在 Jenkins 上运行 Selenium 测试

java - 如何在 Java 类中进行谷歌网页翻译

Java BufferedImage 替代品

java - Spring Boot 中是否有动态可加载模块的模式?

java - 是否有更好的解决方案将大量字段实体映射到两个表中?

java - Spring MVC-存储和检索 @PathVariable Map<String, String>

java - MongoDB + Spring 集成

java - 使用@EnableGlobalMethodSecurity(prePostEnabled = true) 时出错