Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 526
user518066 Avatar asked Oct 30 '22 19:10

user518066


1 Answers

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.

like image 98
Wellington Souza Avatar answered Nov 09 '22 05:11

Wellington Souza