Home >Java >javaTutorial >How to specify springboot external configuration file in multi-jdk environment
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.
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 &
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 &
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 &
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 &
So, what is the difference between the above two startup parameters? --spring.config.additional-location
The 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.
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!