Spring Boot+profile enables different environments to read different configurations

Source: Internet
Author: User
Tags configuration settings

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:

    1. The public configuration of each environment is written in Application.properties, which is read by default.
    2. 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.
    3. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.