I have in src/main/resources the following files
bpp-dev.properties
bpp-prod.properties
bpp-test.properties
Through my STS I can define the key envB, it in two places
- how a
VM argumentsuch as-DenvB=dev - how an
Environmentsuch as VariableenvBand Valueprod
If in a Configuration class I have the following.
@Configuration
@PropertySource("classpath:/com/manuel/jordan/properties/bpp-${envB}.properties")
public class PropertiesConfiguration {
It works fine but always has preference the System Properties over Environment Variables, it is the default behaviour. I have no problem here.
But if I want work explicitly with Environment Variables, the following fails
@Configuration
@PropertySource("classpath:/com/manuel/jordan/properties/bpp-#{systemEnvironment['envB']}.properties")
public class PropertiesConfiguration {
Always I receive:
Caused by: java.io.FileNotFoundException:
class path resource
[com/manuel/jordan/properties/bpp-#{systemEnvironment['envB']}.properties]
cannot be opened because it does not exist
How I can fix this?
If I use the functional @PropertySource and just playing in the same @Configuration class I work with the following:
@Value("#{systemProperties['envB']}")
private String propertiesEnvB;
@Value("#{systemEnvironment['envB']}")
private String environmentEnvB;
to be printed later, both works fine.