Results 1 to 3 of 3

Thread: Spring 3 PropertyOverrideConfigurer with AnnotationConfigApplicationContext

  1. #1
    Join Date
    Feb 2010
    Posts
    2

    Default 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 at 04:36 AM. Reason: formatting

  2. #2
    Join Date
    Oct 2008
    Location
    Poland, Wrocław
    Posts
    428

    Default

    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

  3. #3
    Join Date
    Feb 2010
    Posts
    2

    Default

    Hi

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

    Thanks for your help
    David

Posting Permissions

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