Announcement Announcement Module
Collapse
No announcement yet.
Spring 3 PropertyOverrideConfigurer with AnnotationConfigApplicationContext Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring 3 PropertyOverrideConfigurer with AnnotationConfigApplicationContext

    Hi there,

    I wonder if anyone could clarify the way PropertyOverrideConfigurer works with the spring 3 @Configuration.

    Here are is my @Configuration class:
    Code:
    @Configuration(value = "defaultConfig")
    public class DefaultConfig {
    
    	@Bean()
    	@Lazy(false)
    	public BeanFactoryPostProcessor override() {
    		PropertyOverrideConfigurer configurer = new PropertyOverrideConfigurer();
    		configurer.setLocation(new ClassPathResource("asset.properties"));
    		configurer.setIgnoreInvalidKeys(false);
    		configurer.setIgnoreResourceNotFound(false);
    		configurer.setOrder(0);
    		return configurer;
    	}
    
    	@Bean(name = "assetRepository")
    	@Lazy(false)
    	public IAssetRepository assetRepository() {
    		return new JpaAssetRepository();
    	}
    }
    When using this configuration in the new AnnotationConfigApplicationContext like this:

    Code:
    AnnotationConfigApplicationContext appContext = new AnnotationConfigApplicationContext(DefaultConfig.class);
    I was expecting the following:

    1. an exception to be thrown if there was no file called asset.properties on the classpath or the file exists but the properties incorrectly reference beans.

    2. if the file does exist and has valid properties they would override the properties of other beans defined in this @Configuration class.

    Currently none of the above is happening.

    Please can somebody let me know what I am doing incorrectly?
    Last edited by david.ellis; Feb 3rd, 2010, 05:36 AM. Reason: formatting

  • #2
    Hi

    See also http://jira.springframework.org/browse/SPR-6455 - the problem is that your JavaConfig class creates BeanFactoryPostprocessor and these classes are invoked before getting beans from @Configuration annotated classes.
    Maybe I'm not precise enough - just try Spring 3.0.1 which adds special phase for this case.

    regards
    Grzegorz Grzybek

    Comment


    • #3
      Hi

      Tested on 3.0.1.CI-570 and it appears to work as expected.

      Thanks for your help
      David

      Comment

      Working...
      X