[英]In what order are application.yml read in spring boot?
I suppose that it reads in work working circuit and then it reads in testing circuit .我想它在工作工作电路中读取,然后在测试电路中读取。
If application.yml is in testing circuit , it settings replace the settings has been reading in application.yml of working circuit.如果application.yml在测试电路中,它的设置会替换工作电路的application.yml中已经读取的设置。 If You have defined application-test.yml and you point above a class an annotation @SpringBootTest and above @ActiveProfile("test") then the settings from application-test.yml replaces earlier settings.
如果您已经定义了application-test.yml并且您指向一个类上方的注释@SpringBootTest和上方的@ActiveProfile("test")那么application-test.yml 中的设置将替换之前的设置。
what do you think about all this ?你怎么看这一切? How to understand this process correctly?
如何正确理解这个过程?
Work Circuit : /src/main/resources工作电路:/src/main/resources
Test Circuit : /src/test/resources测试电路:/src/test/resources
application.yaml应用程序.yaml
main:
car:
name: "Audi"
id: "10201"
application-local.yaml应用程序-local.yaml
main:
car:
name: "Mercedes"
id: "10200"
@SpringBootApplication
public class SpringProfilesApplication {
public static void main(String[] args) {
SpringApplication.run(SpringProfilesApplication.class, args);
}
@Bean
CommandLineRunner commandLineRunner(ProfileMain profileMain) {
return args -> {
profileMain.printMainName();
};
}
}
@Component
public class ProfileMain {
@Value("${main.car.name}")
private String name;
@Value("${main.car.id}")
private String id;
public void printMainName() {
System.out.println("\n name in Main application.yaml : " + this.name + "\n");
System.out.println("\n name in Main application.yaml : " + this.id + "\n");
}
}
– When you run the main class, without specifying any profiles, application.yaml will be used. – 运行主类时,不指定任何配置文件,将使用application.yaml 。 – You can specify the profile you need in the development environment
– 可以在开发环境中指定自己需要的profile
Now the settings of those properties that were in the main application.yaml , will be overridden in the specified profile - local .现在,主application.yaml 中的那些属性的设置将在指定的 profile- local 中被覆盖。 If the selected profile does not contain the settings that are in the main application.yaml , then the missing properties will be taken from the main application.yaml .
如果所选配置文件不包含主application.yaml 中的设置,则将从主application.yaml 中获取缺少的属性。
According to Spring Boot reference documentation , the configuration data files are considered in the following order:根据Spring Boot 参考文档,配置数据文件按以下顺序考虑:
you have to put this in your application-test.yml你必须把它放在你的application-test.yml 中
spring:
profiles: test
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.