Application.yml to define beans for jar files

Viewed 1069

I have a Spring boot application and an application.yml file. Now in order to read values from the application.yml I am using @Value annotation and it works fine.

The issue comes, when I try to read the application.yml file from a jar file. I have a jar file, and it is added as a dependency in the my spring boot application, now if I try to read application.yml file from the jar file using @Value I don't get anything.

Is there a way I can read the application.yml using the jar file dependencies?

1 Answers

You could put the application.yml file outside the resources folder of your spring project and read it through any jar.

First boot your spring boot app with this command:

java -jar -Dspring.config.location=<path-to-file> myBootApp.jar

And you can read your file through your other jar by using a YAML library. There are several libraries that you could choose from.

You could also check this article for more info on reading the properties from outside your spring boot app.

Related