Table of contents
question
We often see such configuration in the project's application.yml, as follows:
In Spring Boot, the spring.profiles.active and spring.profiles.include properties are used to configure the profile.
effect
spring.profiles.active
Used to specify the currently selected profile , which can be specified through command line parameters, environment variables, JVM system parameters, etc. In the application.yml or application.properties file, you can also use the spring.profiles.active property to specify the default profile. When the spring.profiles.active property is specified, Spring Boot will use the property value to decide which profile configuration file to load, such as application-prod.yml or application-dev.yml. If this property value is not specified, Spring Boot will default to loading the configuration in the application.yml or application.properties file.
spring.profiles.include
Used to introduce the configuration files of other profiles into the configuration files of one profile . It can be defined anywhere in the application.yml or application.properties file. When the spring.profiles.include attribute is specified, Spring Boot will first load the configuration file of the profile referenced by the attribute, and then load the configuration file of the current profile to overwrite and merge the attributes . You can use commas to separate multiple profile names to indicate the introduction of configuration files for multiple profiles . If an attribute with the same name appears, the attribute in the current profile has a higher priority than the attribute introduced into the profile.
Summarize
In Spring Boot applications, the spring.profiles.active property is used to specify the currently selected profile, and the spring.profiles.include property is used to introduce the configuration of other profiles into the current profile. Both are used to manage profile attributes, but their functions are different.