将覆盖添加到
@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"); ... }}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)