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

What are the ways in which SpringBoot dynamically configures the Profile environment

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

Share

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

Xiaobian to share with you the SpringBoot dynamic configuration Profile environment what are the ways, I believe most people do not know how, so share this article for everyone's reference, I hope you read this article after a great harvest, let's go to understand it!

The following example is an example of dynamically configured port numbers by modifying development and production environments:

Development environment port number is 8081

Production environment port number is 8082

Springboot configuration

Springboot has two configurations: properties and yaml or yml.

properties configuration

1. Configure the environment in application.properties.

Create two application-xx.properties

An application-dev.properties #development environment

An application-pro.properties #production environment

Modify in application.properties.

spring.profiles.active=pro #Switch to production

spring.profiles.active=dev #Switch to development environment

directory structure

2. Modify the environment configuration file by running the jar package

java -jar package file path--spring.profile.active=dev #Switch development environment

java -jar package file path--spring.profile.active =pro #Switch production environment

yaml mode configuration

yaml configuration is simpler than properties: a yaml file can replace the above three properties files; divide the environment by '---' three bars

#---These three bars are equivalent to creating multiple properties files---server: port: 8081spring: profiles: dev #specified environment name--server: port: 8082 spring: profiles: pro #specified environment name--- spring: profiles: active: pro #Configure Environment---

The above is "SpringBoot dynamic configuration Profile environment what are the ways" all the content of this article, thank you for reading! I believe that everyone has a certain understanding, hope to share the content to help everyone, if you still want to learn more knowledge, welcome to pay attention to the industry information channel!

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

Development

Wechat

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

12
Report