The file structure is as follows:
However, the official recommendation is placed under the Config folder.
Role:
Configuration settings for different environments a configuration file, for example: The configuration configuration in the dev environment is in application-dev.properties. Configuration in the PROD environment is configured in Application-prod.properties.
Use:
1, specified in the applicaiton.properties, such as Spring.profiles.active=dev
2. Specify parameters when starting, such as Java-jar Xxx.jar--spring.profiles.active=dev
3. Specify system properties at startup, such as Java-jar Xxx.jar-dspring.profiles.active=dev
Tips for use:
Variables in application.properties can be obtained in such a way:
@Autowired Private Environment env; @RequestMapping ("/testprofile") public String testprofile () { return env.getproperty ("spring.profiles.active"); }
Summarize:
- The public configuration of each environment is written in Application.properties, which is read by default.
- Each module's unique configuration configuration is loaded in its own application-{xxx}.properties file, either by starting the parameter--xxx or by specifying the system Properties-dxxx Or, configure the spring.profiles.active item in Application.properties.
- When the program starts without any designation, the default reads Application.properties, and if specified then reads Application-{xxx}.properties, overwrites Application.properties's entries.
Reference:
Http://www.leftso.com/blog/111.html (This is said in more detail)
http://blog.csdn.net/lazycheerup/article/details/51915185
Spring Boot+profile enables different environments to read different configurations