Search code examples
javaspring-bootconfigurationyaml

Java yaml path to current directory


I'd like to start my Spring boot app with outer config files. I want to put new config file to directory where my jar file before start jar file. I created an outer yaml:

myapp:
  src:
    ip: 111.22.333.444

and an inner yaml:

Spring:
  config:
     import: C:/Users/Igor/Desktop/application.yaml

If I khow my outer yaml path that works very well, but really I don't know path. I want to use path where my jar file started. What can I do for it?


Solution

  • There are many ways to set the location of the yaml file, look in the documentation ==> here

    But in the usual case, you don't need to specify the location/path to the yaml file at all. It is enough that it is nearby (in the same folder as the jar file), Spring will find it itself

    And delete the internal yaml file from the jar file, since you don't need it - Spring will use the external one