In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the Springboot multi-environment development example analysis, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor with you to understand.
Overview
Springboot runs at different stages and may use different environments
For example, in the development stage, testing stage, production stage, application stage
Maybe the environment in which the Springboot project runs in these stages is different, so you can set up a variety of environments in advance and choose to use them according to different scenarios.
Use of multiple environment settings
Method 1:
Write multiple configurations in advance in the yml configuration file, and then choose which one to call
Method 2:
This method also applies to configuration files with the suffix prperties
Set a configuration file for each environment, then write a main configuration file, set which environment to call in the main configuration file, and write the public configuration
It is tantamount to writing each part of method 1 into a separate file.
It should be noted here that the naming of the environment here is different.
The naming method here is: the name of the application- environment, and then there is no need to set the name through spring.profiles in the configuration files of these environment. Of course, if you do not want to use this naming method, you need to set the name through spring.profiles.
The name of the main configuration file starts with application, and in the main file, through the
To invoke the corresponding environment
Multi-environment grouping management
When developing a project, you can set different configuration files for different modules, such as persistence layer, you can set a configuration file called application-devDB, and the MVC layer sets a configuration file called application-devMVC.
Other environments are then managed in the main configuration. Include can load multiple environments to take effect at the same time when the specified environment is activated, separated by commas.
Moreover, if there is the same configuration in multiple environments, the later loaded environment will override the previous loading order: first loading one by one according to the environment in include, and finally loading the environment in active
But for the function of loading multiple environments at the same time to make it effective, the include method is no longer the mainstream, we use group more.
Group configuration files with different names. For example, strings with uppercase application-dev initials can be divided into dev groups, as shown in the figure above.
Then use active to decide which group of configuration files to call
Configuration conflicts between Maven and spring-boot
Spring-boot control based on maven coordinates
So in order to prevent configuration conflicts between maven and spring-boot, we should configure them in maven and let sping-boot read
When Maven and SpringBoot control multiple environments at the same time, Mavn is dominant and SpringBoot uses @. . @ placeholder reads the configuration attribute value corresponding to Maven
First of all, there are several configuration files
Step 1: configure the corresponding multi-environment development in the pom file of maven:
Step 2: reference in springboot
A little BUG of idea
Under the premise of reading Maven configuration attributes based on SpringBoot, if you test under Idea, manual compile is required for each update of pom.xml during the project to take effect.
Thank you for reading this article carefully. I hope the article "sample Analysis of Springboot Multi-Environment Development" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.