user518066
user518066

Reputation: 1417

Add configuration directory to classpath using spring boot

I would like to add a configuration directory to the classpath for a spring boot application at start up, so it can load xml files from the configuration directory.

ie /var/application/config contains test.xml, dev.xml

The xml will contain mapping information that is required by the application; this is different from application.properties.

I would like to load them at startup.

I am using ClassPathResource to load the files.

Please advise.

Upvotes: 6

Views: 13951

Answers (2)

Wellington Souza
Wellington Souza

Reputation: 2358

You can define your own classpath by the command-line. Lets suppose your jar is myapp.jar and you wand add one extra directory /var/application/config/, so you can execute with the following command line:

java -cp myapp.jar:/var/application/config/ -Dloader.main=myapp.Application org.springframework.boot.loader.PropertiesLauncher

ps: if you are using Windows use ; instead of : to separate your classpath items.

Upvotes: 4

Kevin Condon
Kevin Condon

Reputation: 1728

From the Spring Boot Reference Guide, add your config location:

java -jar myproject.jar --spring.config.location=classpath:/var/application/config/

Upvotes: -1

Related Questions