Announcement Announcement Module
No announcement yet.
Confusion - Multiple Property Sources in Spring 3.1 Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Confusion - Multiple Property Sources in Spring 3.1

    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 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/" should be loaded as well (but only if it is there).

    I tried the following:

    @PropertySource(value={"classpath:/", "file:/etc/"})
    public class Config {...}
    This is not working in case there is no /etc/ file.

    The next thing I was trying was to remove the @PropertySource annotation and providing a PropertySourcesPlaceholderConfigurer like this:

    public class Config {
    	private Environment env;
    	public static PropertySourcesPlaceholderConfigurer properties() {
    		PropertySourcesPlaceholderConfigurer pspc = new PropertySourcesPlaceholderConfigurer();
    		Resource[] resources = new Resource[2];
    		resources[0] = new ClassPathResource("");
    		resources[1] = new FileSystemResource("/etc/");
    		return pspc;
    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.

    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,

  • #2
    Nobody there who has the same issue? Topic clear or should I extend my example?