Spring配置文件可以选择@PropertySources吗?

Spring配置文件可以选择@PropertySources吗?,第1张

Spring配置文件可以选择@PropertySources吗?

覆盖添加到

@PropertySource
静态内部类中。不幸的是,你必须一起指定所有属性源,这意味着创建一个“默认”配置文件来替代“替代”。

@Configurationpublic class MyConfiguration{    @Configuration    @Profile("default")    @PropertySource("classpath:defaults.properties")    static class Defaults    { }    @Configuration    @Profile("override")    @PropertySource({"classpath:defaults.properties", "classpath:overrides.properties"})    static class Overrides    {        // nothing needed here if you are only overriding property values    }    @Autowired    private Environment environment;    @Bean    public Bean bean() {        ...        // this.environment.getRequiredProperty("foo");        ...    }}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5110141.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-17
下一篇 2022-11-17

发表评论

登录后才能评论

评论列表(0条)

保存