Announcement Announcement Module
Collapse
No announcement yet.
Application is failing to load the values from properties file. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Application is failing to load the values from properties file.

    Hi,

    I am using maven for packaging my application.

    My springldap.xml has

    <bean id="propertyPlaceHolderPMSServices"
    class="org.springframework.beans.factory.config.Pr opertyPlaceholderConfigurer">
    <property name="locations">
    <list>
    <value>classpath:settings.properties</value>
    </list>
    </property>
    </bean>

    <bean id="contextSource"
    class="org.springframework.ldap.core.support.LdapC ontextSource">

    <property name="url" value="${ldap.host}" />
    </bean>

    I have placed the settings.properties under classpath..But my application is failed to set the values for url property ...instaed it is setting ${ldap.host} as value for url.

    My application throws :
    org.springframework.ldap.UncategorizedLdapExceptio n: Uncategorized exception occured during LDAP processing; nested exception is javax.naming.NamingException: Cannot parse url: ${ldap.host}

    Please advice on the possible mistakes I must be doing at my workspace..

  • #2
    A common mistake is to use BeanFactory instead of ApplicationContext, without realizing what BeanFactory doesn't do for you. To quote the Spring reference manual:

    It is important to know that a BeanFactory treats bean post-processors slightly differently than an ApplicationContext. An ApplicationContext will automatically detect any beans which are deployed into it which implement the BeanPostProcessor interface, and register them as post-processors, to be then called appropriately by the factory on bean creation. Nothing else needs to be done other than deploying the post-processor in a similar fashion to any other bean. On the other hand, when using plain BeanFactories, bean post-processors have to manually be explicitly registered [...]
    You probably have code that looks something like this:

    Code:
    Resource res = new ClassPathResource("/springldap.xml");
    BeanFactory context = new XmlBeanFactory(res);
    If you want to have the PropertyPlaceholderConfigurer registered for you, write this instead:

    Code:
    ApplicationContext context = new ClassPathXmlApplicationContext("/springldap.xml");

    Comment


    • #3
      Hi Ulsa,

      Thanks..

      Using ApplicationContext context = new ClassPathXmlApplicationContext("/springldap.xml"); loads all the beans mentioned in the xml.

      Comment

      Working...
      X