In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article focuses on "springboot configuration development and test environment and add startup path method is what", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Next let the editor to take you to learn "springboot configuration of the development and test environment and add startup path method is what" bar!
Springboot configure the development and test environment and add startup paths
Well, there is a general consensus that the development and test environments should be separated (although none of the companies I have worked for have such a separation), and spring boot can do this according to the reading of the configuration file.
There are three configuration files at the beginning of application in the figure above. To be able to read external configuration files, we need to introduce a dependency package, the one pointed to by the red arrow, and add this section to the node of pom.xml.
Org.springframework.boot spring-boot-configuration-processor true
What's the difference between the three application files? In fact, it's no different, but the name is different.
The name is different. I have configured different ports in it to distinguish, so the application.properties actually read is through the
# the current service environment is the development and test environment spring.profiles.active=dev#spring.profiles.active=prod
To read the development or production environment.
The first line can also configure the root access path of our project, for example, before we add, we access it by localhost:9090/hello in the browser, and after adding / wow, we access it by localhost:9090/wow/hello.
After the development environment and test environment are configured, write a test class controller
@ RestControllerpublic class UserController {@ RequestMapping ("/ getUser") public User getUser () {User user= new User (); user.setId (PlantUuid.moreUuid (1)); user.setName ("ahei"); user.setPwd ("123456"); return user;}}
The utility class PlantUuid is as follows:
Package com.example.util;import java.util.UUID;public class PlantUuid {public static void main (String [] args) {/ / TODO Auto-generated method stub / / moreUuid (10);} / / get 32-bit uuid public static String createUuid32 () {String uuid = "; uuid = UUID.randomUUID (). ToString (). Replace ("-","). ToLowerCase () System.out.print ("- generated uuid is--" + uuid+ "\ n"); return uuid;} / / generate multiple uuid public static String moreUuid (Integer t) {String more_uuid = ""; Integer Kappa 0; for (kudo Tinck test-> online, where the production environment is commonly referred to as the real environment.
Multi-environment configuration
Benefits:
1. Different parameters can be configured in different environment configurations.
two。 Facilitate deployment, improve efficiency, and reduce errors
Properties multi-environment configuration
1. Create three new environment files and write three different ports
Application-dev.properties
Server.port=8888
Application-prod.properties
Server.port=8999
Application-test.properties
Application-test.properties
2. Call in the core configuration file application.properties
Spring.profiles.active=dev
3. Verification: check the console information to see whether the port is the corresponding port.
YAML multi-context configuration application.yml
1. Configure activation options
Spring: profiles:active: dev
2. The configuration file can be distinguished by adding three dashes in English state.
-# New yml file, the name of this file is decspring: profiles: dev#dev configuration server: port: 8888 server: yml # New yml file, the name of this file is testspring: profiles: test#dev configuration server: port: 8899 Murray # New yml file, the name of this file prodspring: profiles: prod#dev configuration server: port: 9999
Comparison of two configuration modes
1. When configuring multiple environments for Properties, you need to add multiple configuration files. YAML only needs one accessory file.
two。 Because of the difference in writing format, yaml is relatively simple and elegant.
3. Disadvantage of YAML: it cannot be loaded through the @ PropertySource annotation. If you need to load values using the @ PropertySource annotation, use the properties file.
Note: both ports cannot be configured at the same time (application-dev.properties and application.yml cannot be configured)
Loading order: the high position will cover the low position.
Location of the initiator class
1. Recommend initiator class under parent package
The first case: initiator class package: com.zl.app, scan note: com.zl.app and its subpackages
2. The initiator class is not located in the parent package
The second case: initiator class package: com.zl.app.main, scan note: com.zl.ap.main and its subpackages
You can add @ ComponentScan (specify the scanned package) to the initiator class
The initiator class, scan comments, is the package where the initiator class is located, and the subpackage
At this point, I believe you have a deeper understanding of "springboot configure the development and test environment and add the startup path method". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue 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.