Spring Boot and external configurations
Boot external config is what you are looking for.
Especially it mentions:
SpringApplication will load properties from
application.properties
files in the following locations and add them to the Spring Environment:
- A /config subdir of the current directory.
- The current directory
- A classpath /config package
- The classpath root
So I would say adding the config folder on classpath is good step. Them it should find application.properties
and load it automatically.
For different config files I use:
@Configuration@EnableAutoConfiguration@PropertySource({ "classpath:path/some.properties", "classpath:another/path/xmlProperties.xml" })public class MyConfiguration { // ...}
Edit:As Dave pointed out (Thank Dave!) there is either -cp or -jar, so you can't add it to classpath like that. But there are options. This should help you to solve the problem: Call "java -jar MyFile.jar" with additional classpath option.
Additionally @PropertySource
doesn't require the resources to be classpath resources if I'm not mistaken.
It should also be mentioned that there is a spring.config.location
parameter that allows one to specify a file system / classpath location for externalized configuration files. This is documented in the following section of the Spring Boot reference guide: