Like the yml
configuration file format of the humanization, but also like properties
the configuration file management way of humanization,
So let's look yml
at how to configure and use a human-like properties
management approach.
Configuration file
Set up spring Boot system yml
and customization yml
files
application.yml
spring: profiles: active: dev include: test #或者 include: "test" application: name: test-yml-application
application-test.yml
test: msg: 这不就是配置文件的内容吗
Based on the use of abstract classes
There are two common ways of
@Value
AbstractCp
publicabstractclass AbstractCp { @Value("${test.msg}") private String msg; publicgetMsg() { return msg; } publicvoidsetMsg(String msg) { this.msg = msg; }}
Cp
@Componentpublicclassextends AbstractCp {}
@ConfigurationProperties
AbstractCp
@EnableConfigurationProperties@ConfigurationProperties("test")publicabstractclass AbstractCp { private String msg; publicgetMsg() { return msg; } publicvoidsetMsg(String msg) { this.msg = msg; }}
Cp
@Componentpublicclassextends AbstractCp {}
Spring Boot introduces Custom yml