Home > Java > javaTutorial > body text

How to specify springboot external configuration file in multi-jdk environment

WBOY
Release: 2023-05-11 16:01:06
forward
1467 people have browsed it

Problem Description

When there are multiple jdk in the deployment environment, and the default jdk version is lower than jdk8. When we deploy springboot applications, we need to specify jdk as jdk8 or above. A problem will arise: the external configuration file of the springboot application cannot be loaded, and it will always use the default configuration file imported into the application jar.

Problem Solving

There are two ways to solve this problem, as follows:

  • Add startup parameters--spring .config.additional-location

nohup /home/jdk1.8.0_251/bin/java -Xms256m -Xmx256m -jar /opt/test-app/jar/service-oa.jar --spring.config.additional-location=/opt/test-app/config/application-dev.yml,/opt/test-app/config/application.yml
 > /opt/test-app/logs/app.log 2>&1 &
Copy after login

Note: --spring.config.additional-location needs to be followed by the full path name, if there are multiple Configuration files can be separated by English commas. In particular, if multiple configuration files are in the same folder, they can also be configured like this:

nohup /home/jdk1.8.0_251/bin/java -Xms256m -Xmx256m -jar /opt/test-app/jar/service-oa.jar --spring.config.additional-location=/opt/test-app/config/ > /opt/test-app/logs/app.log 2>&1 &
Copy after login
  • Add startup parameters--spring.config.location

nohup /home/jdk1.8.0_251/bin/java -Xms256m -Xmx256m -jar /opt/test-app/jar/service-oa.jar --spring.config.location=/opt/test-app/config/application-dev.yml,/opt/test-app/config/application.yml
 > /opt/test-app/logs/app.log 2>&1 &
Copy after login

Note: --spring.config.location needs to be followed by the full path name. If there are multiple configuration files, they can be separated by English commas. In particular, if multiple configuration files are in the same folder, they can also be configured like this:

nohup /home/jdk1.8.0_251/bin/java -Xms256m -Xmx256m -jar /opt/test-app/jar/service-oa.jar --spring.config.location=/opt/test-app/config/ > /opt/test-app/logs/app.log 2>&1 &
Copy after login

Solution comparison

So, what is the difference between the above two startup parameters?
--spring.config.additional-locationThe following configuration file will form a complementary relationship with the default configuration (the configuration file entered in the springboot application jar package), but it has higher priority class.

--spring.config.location The following configuration files are mandatory, that is, once --spring.config.location is added, the default configuration (springboot application jar The configuration file entered in the package) will be invalid, and the configuration file after --spring.config.location shall prevail.

Note

In lower versions of springboot, --spring.config.additional-location will not take effect. At this time, you can only use
--spring.config.location is gone.
For example: In the springboot 2.3.6.RELEASE version, --spring.config.additional-location will not take effect.

The above is the detailed content of How to specify springboot external configuration file in multi-jdk environment. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template