The java startup jar package introduces external configuration files

premise:

The typed jar already contains each application-xxx.yml file, and the location of the jar also introduces the external application-test.yml.

Purpose: When running, you want to use the external application-test.yml file.

The following commands were used:

java -Xms1024m -Xmx2048m -jar  /home/test/my-test-app-0.0.1.jar  --spring.config.location=./application-test.yml  --logging.config=./logback.xml  -server my-test-app &

It can be started, but the application-test.yml configuration in the jar package is used instead of the external application-test.yml file.

Solve the problem:

Use the -D command to set system properties

java -Xms1024m -Xmx2048m -jar  -Dspring.config.location=./application-test.yml /home/test/my-test-app-0.0.1.jar   --logging.config=./logback.xml  -server my-test-app &

or:

java -Xms1024m -Xmx2048m -jar  -Dspring.config.location=./application-test.yml -Dlogging.config=./logback.xml /home/test/my-test-app-0.0.1.jar -server my-test-app &

When starting, if you start directly in the directory where the jar package is located, such as java -jar, then it will automatically load config or the configuration file (properties, yml) in the root directory. If you use the script startup method, then your execution script
may The path and the path where the script is located are not in the same directory, then you can use an absolute path to configure at this time, for example:

java -jar ./test.jar --spring.config.additional-location=../config/ --spring.profiles.active=dev

spring.config.location: will override internal configuration parameters
spring.config.additional-location: will be complementary to internal configuration parameters

question:

During the test process, if the imported application file contains the spring.profile attribute, the reference will fail, so this file needs to be deleted. If you need to use spring.profile, you need to add this configuration item to the startup script:

java -Xms1024m -Xmx2048m -jar  -Dspring.config.location=./application-test.yml -Dlogging.config=./logback.xml /home/test/my-test-app-0.0.1.jar --spring.profile=test -server my-test-app &

Guess you like

Origin blog.csdn.net/qq_34484062/article/details/128021066