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

How to configure SpringBoot multi-module and multi-environment profile

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

The knowledge of this article "how to configure SpringBoot multi-module multi-environment configuration file" is not understood by most people, so the editor summarizes the following contents, detailed contents, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "how to configure SpringBoot multi-module multi-environment configuration file" article.

The first situation:

Spring.profiles.active= environment variable

If you configure two environments, you can add environment patterns according to actual needs (development environment dev, test environment test, regression environment retu, pre-production environment pre, production environment prod, etc.)

Configure profiles in pom.xml:

Dev true dev prod prod

System environment variable configuration:

Locally, if you configure the port and path in these files:

Appilacton.yml:

Server: port: 8087 servlet: context-path: / miservice

Application-dev.yml:

Server: port: 8088 servlet: context-path: / miservice-dev

Application-prod.yml:

Server: port: 8087 servlet: context-path: / miservice

Valid is: 8088 of the configuration.

Locally, if the sub-environment is not configured, it will be dominated by the primary environment:

Appilacton.yml:

Server: port: 8087 servlet: context-path: / miservice

Application-prod.yml:

Server: port: 8089 servlet: context-path: / miservice-prod

It's 8087. This is valid.

Summary 1:

The application.yml introduction configuration is as follows:

Spring: profiles: active: ${env}

That is, the read order of configuration is: application.yml > > application-dev.yml

The second situation:

If you want the configuration files of multiple modules to work, you can configure the application.yml file to a specific module:

Spring: profiles: active: miservice, ${env}

In application.yml, application-miservice.yml and application-dev.yml files: if there is a port or path configuration, read the configuration in application-dev.yml, close the configuration in application-dev.yml, read the configuration in application-miservice.yml, and finally read application.yml.

The configuration inside.

The application.yml introduction configuration is as follows:

Spring: profiles: active: miservice, ${env}

That is, the read order of configuration is: application-dev.yml > > application-miservice.yml > > application.yml

Revise it: the above conclusion is summarized at the beginning, and later it is found that the reading order is read from bottom to top in the order of the file. That is, in structural order.

The above is the content of this article on "how to configure SpringBoot multi-module and multi-environment configuration file". I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more related knowledge, please 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