Reputation: 3310
I'd like to completely externalize my config files so that every *.properties file is in /etc/foo/.
But I don't want everything in one big application.properties so I split certain parts away into individual *.properties files.
How can I tell @PropertySource that it should resolve the location of the given property file exactly as it would do for its application.properties i.e. search for it in every directly (could be multiple) that I specified with "--spring.config.location"?
My class would ideally look this way:
@Configuration
@PropertySource("dpuProfiles.properties")
@ConfigurationProperties("dpu.profiles")
public class DpuProfilesConfiguration {
...
}
It does work if I explicitly specify "file:/etc/foo/dpuProfiles.properties". I couldn't get "${spring.config.location}/dpuProfiles.properties" or similar substitution with EL working. Makes probably no sense either as the variable could contain multiple directories.
Upvotes: 1
Views: 831
Reputation: 2447
You can do it by specify the the config(s) directory in your -classpath
and point it from classpath to your @PropertySource
For your case it will be
CLASSPATH=just_added_as_an_example_jar.jar:/etc/foo/
-classpath "$CLASSPATH"
But you need to change the @PropertySource
value as follows
@PropertySource({"classpath:dpuProfiles.properties"})
@ConfigurationProperties({"classpath:dpu.profiles"})
Note - The above example is to run from script.
Upvotes: 2