Having this class to override an already set @PropertySource in another Config class.
@Configuration
@PropertySource({ "classpath:${env.placeholder}/app.properties" })
public class PropertyOverrideConfig {
}
But whenever the file or placeholder is missing, its failing the context loading. I need to set the following flags to that annotation loaded property, so that it will skip, if its not able to find the property.
setIgnoreResourceNotFound(true);
setIgnoreUnresolvablePlaceholders(true);
Question1: What would be the appropriate way to set these flags for the @PropertySource?
Updates: Tried adding a @Bean to the same class without that annotation referring this page, it ain't picking the property file either. I don't have an xml configuration.
@Bean
public static PropertySourcesPlaceholderConfigurer properties() {
final PropertySourcesPlaceholderConfigurer pspc = new PropertySourcesPlaceholderConfigurer();
Resource[] resources = new ClassPathResource[ ] {
new ClassPathResource( "classpath:${env.placeholder}/app.properties" ) };
pspc.setLocations( resources );
pspc.setIgnoreResourceNotFound(true);
pspc.setIgnoreUnresolvablePlaceholders(true);
return pspc;
}
Question2: I am sure I'm missing something, but couldn't figure out what it is, any help would be great.
I think I finally figured out the answer for the Question1:
How to set Ignore flags for properties added through @PropertySource
?
Its not there in Spring still, its been proposed as an Minor Improvement. Hopefully will be able to see an additional attribute added to the annotation soon in future release.
SPR-8371
Still not sure about the way to accomplish the scenario mentioned and no answer for Question2.
Not really a solution, but a workaround, if you have to stick to Spring 3: use a dummy default, which exists, i.e. in your case:
@PropertySource({ "classpath:${env.placeholder:dummy}/app.properties" })
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With