In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article is to share with you about the problems with shared configuration files in springboot multiple modules. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
This problem is encountered in the springboot multi-module shared profile project.
Some parameters of the common module comm are configured in the configuration file, and other applications rely on the comm package, so that each application needs to be configured with the same parameters as comm, otherwise an error will be reported when starting. Unable to find configuration parameter, unresolved exception:
Is there any way to meet such a demand?
Common module comm, configured with parameters, application A depends on comm. If the same parameters are configured in A, the parameters set in comm will be overridden. If not set in A, then the parameters in comm will be used?
After half an hour of testing, the answer is yes:
1. The architecture sketch is shown in the figure:
2 、 application.yml:
3. After testing, dev, that is to say, the upper configuration files should be placed at the back.
It overrides the same parameters as before, and if it is not configured in the later configuration file, it uses the common parameters of the commdev common module.
Loading of yml configuration file under springboot multi-module
If your project has multiple modules, for example, several projects share a data module (DataModule), and the API part is a module (APIModule). If you want to switch different environments, you need to set different database addresses. If the data is distributed in multiple data sources, manually modifying the addresses in yml is obviously impractical and error-prone, so you need to put different data sources in different yml and modify the configuration in a yml at compile time.
Specific examples are as follows
There is application.yml under APIModule. If the environment is different, the configuration of this module needs to be different, so you can add application-development.yml (development environment) and application-product.yml (production environment).
To load one of these, you need to configure spring.profiles.active in application.yml to development (the configuration file starts with application-). However, if the naming rules of the yml files under your DataModule are the same as those of APIModule, you will find that the data module configuration cannot be read.
At this point, you must rename the conflicting names, for example, change the yml file of Datamodule to application-datadevelopment.yml and application-dataproduct.yml and add datadevelopment to spring.profiles.active in the application.yml file of APIModule to load the dev configuration of these two modules.
Similarly, to change to a production environment, spring.profiles.active is product,dataproduct.
Thank you for reading! On "springboot multi-module shared configuration files will encounter what problems" this article is shared here, I hope the above content can be of some help to you, so that you can learn more knowledge, if you think the article is good, you can share it out for more people to see it!
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.