java @PropertySource值覆盖

k10s72fa  于 2023-05-12  发布在  Java
关注(0)|答案(2)|浏览(130)

我试图有2个外部文件为我的应用程序配置,一个与我所有的应用程序和一个与每个应用程序的具体事情的共同属性。
在我的Springboot App中,我声明:

@PropertySource(value = {"file:/etc/company/application.properties",
        "file:/etc/company/myApp/application.properties"}, ignoreResourceNotFound = true)

在日志中,

Converting PropertySource applicationConfig: [classpath:/application.properties] [org.springframework.boot.env.OriginTrackedMapPropertySource] to EncryptableMapPropertySourceWrapper
Converting PropertySource URL [file:/etc/company/myApp/application.properties] [org.springframework.core.io.support.ResourcePropertySource] to EncryptableMapPropertySourceWrapper
Converting PropertySource URL [file:/etc/company/application.properties] [org.springframework.core.io.support.ResourcePropertySource] to EncryptableMapPropertySourceWrapper

而来自**/etc/company/www.example.com的属性是要考虑的。application.propertiesare the ones taken into account.. This is the exact inverse of what is mentioned in PropertySource javadoc.
我是不是漏掉了什么?

dm7nw8vv

dm7nw8vv1#

经过多次调查,似乎Spring或Sping Boot 都没有确保属性源加载的顺序。我删除了我的属性继承:1个应用程序,1个app.properties文件。

9nvpjoqh

9nvpjoqh2#

一个已知的解决方法是将application.properties重命名为其他名称(例如app.properties)。这时覆盖工作正常。
但我承认这不是一个适当的解决这个问题,可能不会在某些情况下工作。
来源:Maksim Muruev(mmuruev)在@PropertySource中的评论未按顺序覆盖[SPR-13500]。

相关问题