Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting spring.config.location as a relative path

Is it possible to use relative path in spring.config.location ?

I have the following structure in IntelliJ

|-dev.yml
|-src
  |-main
  |-java
    |-com.foo
      |-MySpringApp.java

and run it with

--spring.config.location=dev.yml

which doesn't work

The only thing that works is setting full path

--spring.config.location=/user/.../myApp/dev.yml
like image 600
bodziec Avatar asked Mar 11 '23 16:03

bodziec


1 Answers

Strange no-one ever answered this.

I just worked it out myself by trial and error.

A relative path is always going to work because Java is running from some directory wherever and whenever you run it. Just a case of discovering what it is.

In my case with Win10, Java 1.8, IntelliJ 2018 and Spring Boot 2.0.2, running my app as a Spring Boot app in IntelliJ, my relative path is relative to the project root.

So for you, I would assume that it starts out the same way, using the project root. Since that is where your properties are, you need ., and then since it is a directory, you need to append a slash on the end:

--spring.config.location=./
like image 191
Adam Avatar answered Mar 20 '23 09:03

Adam