Results 1 to 2 of 2

Thread: Confusion - Multiple Property Sources in Spring 3.1

Hybrid View

  1. #1
    Join Date
    Oct 2007
    Posts
    11

    Default 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 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:

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

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

    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;
    	}
    }
    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,
    fr

  2. #2
    Join Date
    Oct 2007
    Posts
    11

    Default

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •