Hi guys,
I'm a bit confused with the new property sources. What I want to do is the following:
As per default, there is an environment.properties file in my classpath. This one should be used always as default. In order to be able to override some properties, an optional file "/etc/env.properties" should be loaded as well (but only if it is there).
I tried the following:
This is not working in case there is no /etc/env.properties file.Code:@PropertySource(value={"classpath:/environment.properties", "file:/etc/env.properties"}) public class Config {...}
The next thing I was trying was to remove the @PropertySource annotation and providing a PropertySourcesPlaceholderConfigurer like this:
This was basically working, BUT whenever I try to load a property from the Environment, I was not able to find any of my configured propertySources. The content of my environment shows the following list of propertySources: ([servletConfigInitParams,servletContextInitParams,j ndiProperties,systemProperties,systemEnvironment]). So my configured sources are missing.Code:@Configuration public class Config { @Autowired private Environment env; @Bean public static PropertySourcesPlaceholderConfigurer properties() { PropertySourcesPlaceholderConfigurer pspc = new PropertySourcesPlaceholderConfigurer(); Resource[] resources = new Resource[2]; resources[0] = new ClassPathResource("environment.properties"); resources[1] = new FileSystemResource("/etc/env.properties"); pspc.setLocations(resources); pspc.setIgnoreResourceNotFound(true); return pspc; } }
As I read, there is no way to use the @PropertySource Annotation and to define the IgnoreResourceNotFound setting. So what is the best way to solve my problem?
Best regards,
fr


Reply With Quote