简体   繁体   中英

How to load application.properties file in another path?

I have a spring boot web app but I want to load the application.properties file in another path because it has private information about database connection string.

Here are things what I did:

  1. Remove the application.properties file in the default path like this:
src
   main
       resources
           application.properties
  1. I tried a kind of command line (I use gradle not maven):
> gradle clean assemble
> java -jar -Dspring.config.location=<Insert the path here> build/libs/<jar-file>

As usual. The code would run with the configuration of application.properties file as my desire. But many changes later seems doesn't save and still run old code before it has changed. How to solve it?

You can try find the answer here . Try to use other profile configure file and override what you need within.

Or if there are just a few things to change, you can override them without properties file. For example:

./gradlew run --args='--server.port=8080'

or

java -jar -Dserver.port=8080 app.jar

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM