Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

SpringBoot-spring.profiles.active partition configuration

2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report