In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the knowledge of "how to switch between startup development environment and test environment with SpringBoot framework". Many people will encounter this dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
SpringBoot framework switches the directory structure of startup development environment and test environment
1. Add the plug-in dev true dev test test prod prod ${project.basedir} / src/main/resources to the pom.xml file True org.springframework.boot spring-boot-maven-plugin repackage
Note:
True
Put it under dev and start it in the development environment by default, as shown above. If you want to start it in a test environment, cut the above code to test.
two。 Add profile application.yml
For post-viewing which environment is used to start the project
3. Add the profile application-test.yml for the test environment
Switch the development address of database, dubbo and redis to the test address.
4. A shortcut to package a project into a jar package
We package the project into a jar package and package the subproject (scm-bms-starter) containing the startup file (BmsApplication).
This is the jar bag we want.
Let's test whether the jar package can be run
First, in cmd, change the directory to the path where the jar package is stored
Then, run the jar package
Command 1:java-jar scm-bms-starter-0.0.1-SNAPSHOT.jar (windows)
Command 2:nohup java-jar scm-bms-starter-0.0.1-SNAPSHOT.jar & (linux)
The difference between the two:
Command 1 outputs the startup process on the console, and when cmd is turned off, the process is killed automatically
Command 2 will start the project in the background and enter the startup process into a default file (nohup.out). The process will not end with the shutdown of the console. You need to use kill-15 pid to kill the process.
SpringBoot dynamic switching environment
Generally speaking, we will have the classification of development, testing, pre-production and production environment in the development. At this time, we will encounter the need to dynamically switch the environment when the project is deployed and packaged. How to achieve the switching of the dynamic environment? All right, don't talk too much nonsense and go straight to practical information.
1. We add the environment configuration in the project to the pom.xml of springboot.
As shown in the picture
We first briefly introduce the switching of the three sets of environments, as shown in the figure, when we add the profile configuration of the three sets of environments, our first phase of the task is completed, that is, the configuration of the environment.
2. After the environment configuration is completed, we have three sets of environments.
We need three application-xxx.properties files from copy and put them in the same directory as application.properties, which is the default configuration of springboot. The main configuration file application.properties leaves only one configuration of spring.profiles.active=@env@. Here the variable evn gets the value of the tag in the above figure profile. Its value is related to the commands of your copy's three configuration files, xxx. This should be noted. For the other three application-xxx.properties files, we can only change the port number of their tomcat to be different for testing. Attached picture:
Master profile:
Development environment profile:
Well, the other configuration files don't go into detail, but simply change the port number of the launched tomcat in order to see the effect.
3. Depending on the effect, we choose the configuration of the development environment to start, and pay attention to the startup information. Attached picture:
This is the end of the content of "how to switch between startup development environment and test environment with SpringBoot framework". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.