Overview
I tried to put the same configuration in bootstrap.yaml and application.yaml, and then get the configuration value through @Value. The result is the configuration in application.yaml. Normally, the priority of bootstrap.yaml should be I am surprised that it is greater than application.yaml, but in the process of debugging the code, I found that the priority of bootstrap.yaml is almost the lowest. I want to confirm why?
Environment
- Springboot 2.6.11
- SpringCloud 2021.0.4
- jdk 8
Detail
bootstrap.yaml
server:
port: 30000
common: bootstrap.yaml
application.yaml
server:
port: 30001
common: application.yaml
result
@SpringBootTest(classes = Main.class)
public class MainTest {
private String commonValue;
@Value("${common}")
public void setCommonValue(String commonValue) {
this.commonValue = commonValue;
}
@Test
public void test() {
System.out.println(commonValue);
//output: application.yaml
}
}
Question
Why does the configuration in application.yaml take precedence over bootstrap.yaml?
Comment From: wilkinsona
Support for bootstrap.yaml is a Spring Cloud feature. You may want to ask on Stack Overflow, or if you think you've found a bug, raise a Spring Cloud issue.