bodziec
bodziec

Reputation: 594

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

Upvotes: 6

Views: 15611

Answers (2)

Adam
Adam

Reputation: 5445

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=./

Upvotes: 10

DwB
DwB

Reputation: 38290

Read this spring boot configuration chapter

I don't know about relative paths, but you can use classpath:dev.yml if you put the dev.yml file in the classpath.

Upvotes: 0

Related Questions