0

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?

Higanbana
  • 489
  • 10
  • 26
  • 1
    *But many changes later seems doesn't save and still run old code before it has changed*: what does that mean? What are you doing, what do you expect to happen, what happens instead? – JB Nizet Jul 11 '19 at 06:30
  • your title and the GIST of questions are very different, title says *how to load...in another path* while your content ask *how to hide...* – Vishwa Ratna Jul 11 '19 at 06:35
  • @JBNizet I mean when I make any change in my code and saved, as usual it would run as the changed code. But this is different, it still run as the old code does – Higanbana Jul 11 '19 at 06:39
  • @ExceptionHandler Sorry for the misunderstanding. I'd edit that – Higanbana Jul 11 '19 at 06:41
  • Well, if, to run, you use the command above (java -jar ...), then of course you must rebuild the jar before running. – JB Nizet Jul 11 '19 at 06:44
  • You can try find the answer [here](https://stackoverflow.com/questions/23563363/how-to-override-application-properties-during-production-in-spring-boot) – lczapski Jul 11 '19 at 06:53
  • @JBNizet yup but I use `gradle clean assemble` to rebuild. isn't it? – Higanbana Jul 11 '19 at 07:00
  • That question is hardly `application.properties` related\ – Antoniossss Jul 11 '19 at 07:03
  • @HarryCoder remove whole buit app by hand and see what will happen – Antoniossss Jul 11 '19 at 07:04
  • @Antoniossss I know this is really hard but I wanna hide it so my colleague wouldn't know where the file is – Higanbana Jul 11 '19 at 07:05
  • There is nothing hard in it. You can place `application.properties` next to jar file and it will work ouf of the box. You would know that if you would read spring docs regarding externalized configuration. What you have here is that you don't know how rebuilt your project or where it is build and you are using old assembly. Thats why I am voting to close as 95% of content and missleading title says you have problem with configuration - which you says it works fine anyway - while having problem with rebuilding application. – Antoniossss Jul 11 '19 at 07:12
  • @Antoniossss I'm sorry for my non-coherent question. If you can, please edit it or tell me to make this better. – Higanbana Jul 11 '19 at 07:21
  • Close it and ask why it is using old codebase. – Antoniossss Jul 11 '19 at 07:24

1 Answers1

0

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
lczapski
  • 4,026
  • 3
  • 16
  • 32