1. Core configuration of Spring boot
After the spring boot project is established, the Application.properties configuration file has been created
In fact, the configuration file also supports *.YML format;
2. configuration file for multi-configuration environment (actual development)
Application-dev.properties
Application-test.properties
Application-online.properties
Multi-environment configuration file, at this time we need to configure the application.properties, to activate one of the configuration files, the configuration is as follows:
Spring.profiles.active=dev (development environment)
So the problem is, if the development environment is configured with Port 8089, the application.properties is also configured with 8080, and finally the port that is in effect for development environment 8089
3. Spring Boot Custom configuration file
Configure the configuration you want in application.properties, then use the @value annotation in Cotnroller to get the value of the custom configuration
And get it in the controller.
Another way to read a custom configuration
Define a class, then read the value into the properties of the class, and then call the class's properties to get the configuration
/*** Define values in custom attributes*/@Component @configurationproperties (prefix= "Boot") Public classConfiginfo {PrivateString Country; Private intAge ; PublicString getcountry () {returnCountry; } Public voidSetcountry (String country) { This. Country =Country; } Public intGetage () {returnAge ; } Public voidSetage (intAge ) { This. Age =Age ; }}
@Controller Public classConfigcontroller {@Value ("${boot.country}") PrivateString Country; @RequestMapping ("/boot/config") Public@ResponseBody String config () {returnCountry; } @AutowiredPrivateConfiginfo Configinfo; @RequestMapping ("/boot/config2") Public@ResponseBody String Config2 () {returnConfiginfo.getcountry () +Configinfo.getage (); } }
() Spring Boot configuration