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-locationneeds 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.locationneeds 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-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.locationThe following configuration files are mandatory, that is, once--spring.config.locationis added, the default configuration (springboot application jar The configuration file entered in the package) will be invalid, and the configuration file after--spring.config.locationshall prevail.
In lower versions of springboot,--spring.config.additional-locationwill not take effect. At this time, you can only use--spring.config.locationis gone.
For example: In the springboot 2.3.6.RELEASE version,--spring.config.additional-locationwill 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!
jdk8 new features
jdk environment variable configuration
SpringBoot project building steps
How to configure jdk environment variables
Configure Java runtime environment
What is the difference between j2ee and springboot
How to import mdf files into database
Why disabling automatic updates in Windows 11 is invalid