Announcement Announcement Module
Collapse
No announcement yet.
PropertyPlaceholderConfigurer doesnt load properties with applicationContext Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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, 10:29 AM. Reason: Update code

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

    Joerg

    Comment


    • #3
      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.

      Comment


      • #4
        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, 11:14 AM.

        Comment


        • #5
          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>

          Comment


          • #6
            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();

            Comment

            Working...
            X