The Spring boot configuration file is available in two formats: Application.properties and APPLICATION.YML. Only one of the two profiles needs to be used.
There are some differences in the syntax of the two configuration files, as follows
1. Application.properties
Server.port = 8080--Tomcat port
Server.context-path =/webname--URL path
2. Application.yml
Server
port:8080--Tomcat port, note that there are spaces after the colon
Context-path:/webname--URL path, note that there are spaces after the colon
One, the Java class uses the configuration
1. Method One
@value ("${server.port}")private String port;
2. Method Two
@Compoent @configurationproperties (prefix= "server") Public class serverproperties{ private String port; Private String context-path; // Set/get method }
Note: Using annotations @Compoent is to facilitate the use of @autowired in other classes to reference the class
Second, sub-environment use configuration file
Create two more Profiles application-dev.yml (test environment Profile) and APPLICATION-PROD.YML (formal environment profile)
The configuration in Application.yml is as follows:
Spring: Profiles: Active:dev
Note: The above configuration is to use the configuration file application-dev.yml, change to Active:prod can use the configuration file application-prod.yml
Third, Java command start using configuration
Java-jar ****.jar--spring.profiles.active=dev
Note: The above configuration is to use the configuration file application-dev.yml, change to--spring.profiles.active=prod can use the configuration file application-prod.yml
Spring Boot Learning--spring boot configuration file application