【问题标题】:In Spring Boot how to use the properties from different configuration files at the same time?在 Spring Boot 中如何同时使用来自不同配置文件的属性?
【发布时间】:2021-04-06 19:51:34
【问题描述】:

我有一个application.yml 文件和一个sensitive-data.yml。我希望将这些文件中的属性一起使用。有什么办法吗?

【问题讨论】:

    标签: spring-boot


    【解决方案1】:

    使用可以使用@PropertySource

    @PropertySource("classpath:foo.properties")
    @PropertySource("classpath:bar.properties")
    public class PropertiesWithJavaConfig {
        //...
    }
    

    此链接将为您提供帮助:https://www.baeldung.com/properties-with-spring

    【讨论】:

    • 首先,我有 yml 文件,如果我没记错的话,PropertySource 只适用于属性文件。另外,如果这可以在代码之外完成,我会很感兴趣。
    • 也许这种方法可行:stackoverflow.com/questions/23134869/…
    • 我将此标记为已接受,因为它解决了我的问题,但我仍在等待更合适的解决方案。
    猜你喜欢
    • 2018-07-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-28
    • 2016-08-15
    • 2019-02-20
    • 2019-04-22
    • 1970-01-01
    相关资源
    最近更新 更多