Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

SpringBoot-spring.profiles.active partition configuration

Shulou Source: shulou.com Published: 2022-06-03 07:47:54 11月23日 Update

Profiles of Spring Boot is used for partition configuration

Benefit: you can switch between different environments through spring.profiles.active

Configuration location: application.properties under Spring Boot project

Configuration format: (application- {profile} .properties) loads the corresponding configuration file according to the configuration by default

Example configuration:

Application-dev.properties

Application-test.properties

Application-prod.properties

Spring.profiles.active=test now reads the application-test-properties file spring.profiles.active: prod,proddb,prodmq to activate three configurations at the same time

Extension: spring.profiles.include for overlaying profile

Configure loading mode

Switch environment invocation by calling execution command in application.properties

Usually, the second method is more suitable for formal research and development, and the code is as follows:

1. Change application.xml

Change from spring.profiles.active=dev to spring.profiles.active=@profileActive@

2. Change pom.xml

Dev

Dev

True

Compile

True

Test

Test

True

Provided

Demo

Demo

True

Provided

Pro

Pro

True

Provided

3. Execute commands when maven is packaged

Mvn clean × × tall-Dmaven.test.skip=true-Ptest

4. Execute commands in application

-Dspring.profiles.active=dev

Tags: Configuration command file mode environment switch different three code location can be passed at the same time benefit situation time format activation example project solid Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Linux Microsoft Shulou Information vpn