Слияние работает отлично!
Дано:
@SpringBootApplication
public class SoYamlSpringProfileMergeApplication {
private final Data data;
public SoYamlSpringProfileMergeApplication(Data data) {
this.data = data;
}
@EventListener(ApplicationReadyEvent.class)
public void showData() {
System.err.println(data.getOne());
System.err.println(data.getTwo());
System.err.println(data.getThree());
}
public static void main(String[] args) {
SpringApplication.run(SoYamlSpringProfileMergeApplication.class, args);
}
}
@Component
@ConfigurationProperties(prefix = "data")
class Data {
private String one = "one default";
private String two = "two default";
private String three = "three default";
public String getOne() {
return one;
}
public String getTwo() {
return two;
}
public String getThree() {
return three;
}
public void setOne(String one) {
this.one = one;
}
public void setTwo(String two) {
this.two = two;
}
public void setThree(String three) {
this.three = three;
}
}
и
spring:
profiles:
active: "other"
---
spring:
profiles: dev
data:
one: one dev
two: two dev
---
spring:
profiles: prod
data:
one: one prod
two: two prod
---
spring:
profiles: other
data:
three: three other
напечатает:
one dev
two dev
three other
и с:
spring:
profiles:
active: "other,prod"
one prod
two prod
three other
важно порядок активен: "прочее, прод" имеет значение!
с использованием
spring:
profiles:
active: "prod,other"
выдаст
one dev
two dev
three other
- загрузить реквизит из 'prod'
- объединить с реквизитами 'other' объединить значения dev