Results 1 to 6 of 6

Thread: PropertyPlaceholderConfigurer doesnt load properties with applicationContext

  1. #1
    Join Date
    Jan 2008
    Location
    canada
    Posts
    5

    Default PropertyPlaceholderConfigurer doesnt load properties with applicationContext

    Hi,

    I try to use the PropertyPlaceholderConfigurer.postProcessBeanFacto ry() method, but it doesn't seems to work with the properties object setProperties().

    Code:
    PropertyPlaceholderConfigurer configurer = new PropertyPlaceholderConfigurer();
    AbstractApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
    
    ResourceLoader resourceLoader = new DefaultResourceLoader();
    Resource resource = resourceLoader.getResource("classpath:default.properties");
    Properties properties = new Properties();
    prop.load(resource.getInputStream());
    
    configurer.setProperties(properties);
    
    configurer.postProcessBeanFactory(context.getBeanFactory());
    In my log nothing appear....

    But if i use the setLocation() it works

    Code:
    PropertyPlaceholderConfigurer configurer = new PropertyPlaceholderConfigurer();
    AbstractApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
    
    ResourceLoader resourceLoader = new DefaultResourceLoader();
    Resource resource = resourceLoader.getResource("classpath:default.properties");
    configurer.setLocation(resource);
    
    configurer.postProcessBeanFactory(context.getBeanFactory());
    18:19:40,129 INFO PropertyPlaceholderConfigurer:174 - Loading properties file from class path resource [default.properties]
    Somebody have noticed that before - It is a bug ?
    I use spring 2.5

    I really need an applicationContext class for the shutdownHook(), i cannot use the XmlBeanFactory (i use the properties object and it works).

    if i use the XMLBeanFactory with setProperties() it's working :


    Code:
    PropertyPlaceholderConfigurer configurer = new PropertyPlaceholderConfigurer();
    factory = new XmlBeanFactory(new ClassPathResource(applicationContextFile));
    
    ResourceLoader resourceLoader = new DefaultResourceLoader();
    Resource resource = resourceLoader.getResource("classpath:default.properties");
    Properties properties = new Properties();
    prop.load(resource.getInputStream());
    
    configurer.setProperties(properties);
    
    configurer.postProcessBeanFactory(factory);
    Last edited by regis.dev; Jan 10th, 2008 at 09:29 AM. Reason: Update code
    Junit - code less, bling more

  2. #2
    Join Date
    Nov 2005
    Location
    Reutlingen, Germany
    Posts
    2,098

    Default

    You don't want to STORE the properties to the file but LOAD them from the file.

    Joerg
    This post can contain insufficient information.

  3. #3
    Join Date
    Jan 2008
    Location
    canada
    Posts
    5

    Default

    thanks for the answer but it was a bad copy/paste sample, but i still have the error,
    i update my code, in this case it should work i really don't understand.

    If somebody have a clue i will really appreciate.
    Junit - code less, bling more

  4. #4
    Join Date
    Jan 2008
    Location
    canada
    Posts
    5

    Default

    I found the solution

    Replace
    Code:
    configurer.postProcessBeanFactory(context.getBeanFactory());
    By
    Code:
    context.addBeanFactoryPostProcessor(configurer);
    context.refresh();
    Last edited by regis.dev; Jan 10th, 2008 at 10:14 AM.
    Junit - code less, bling more

  5. #5
    Join Date
    Jan 2008
    Location
    canada
    Posts
    5

    Default

    I found another solution if you want to keep

    Code:
    configurer.postProcessBeanFactory(context.getBeanFactory());
    put in your applicationContext.xml

    Code:
    <beans ... default-lazy-init="true">
    ...
    </beans>
    Junit - code less, bling more

  6. #6
    Join Date
    Oct 2007
    Posts
    142

    Default Example with ClassPathXmlApplicationContext

    Here is an example of code

    Code:
    PropertyPlaceholderConfigurer configurer = new PropertyPlaceholderConfigurer();
    configurer.setLocation(new ClassPathResource("context.properties"));
    
    ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(new String[]{"applicationContext.xml"}, false);
    applicationContext.addBeanFactoryPostProcessor(configurer);
    applicationContext.refresh();

Posting Permissions

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