1. Configuration Files
1) application.properties (core configuration file)
Test.a= a_properties
test.b = b_${test.a}
2) application.yml (core configuration file)
Test:
A.yml
b_${test.a}
c.yml
d_${test.c}
3) other.properties (normal configuration file)
Other.config= This is common config!
4) Read property values in class
@Value ("${test.a}")
private String A;
@Value ("${test.b}")
private String B;
@Value ("${test.c}")
private String C;
@Value ("${test.d}")
private String D;
private static String other;
static {
ResourceBundle Obundle = Resourcebundle.getbundle ("other");
other = Obundle.getstring ("Other.config");
}
@GetMapping ("/test") public
String Testconfig () {
return a + ";" + B + ";" + C + ";" + D + ";" + oth er;
}
Note: application.properties and application.yml are automatically loaded, the same configuration takes precedence with the value set in Application.properties , toggle Profile , 2 1) Default configuration: Application.yml
Config:
This is the default config!
# config file switch
#spring:
# Profiles:
# Active:test
2) test environment configuration: application-test.yml
Config:
This is Test config!
3) Production environment configuration: Application-prod.yml
Config:
This is produce config!
3. Set Context-path and port number
#设置context-path and port numbers, default to "/" and 8080
server:
/
v 18080