title: Spring, JndiTemplate externalizing provider URL
body: <p>My project requires the Initial Context Factory and the provider URL to be loaded from a properties file. Here is my Spring configuration</p>
  
  <pre><code>&lt;bean id="jndiTemplate" class="org.springframework.jndi.JndiTemplate" lazy-init="true"&gt;
      &lt;property name="environment"&gt;
          &lt;props&gt;
              &lt;prop key="java.naming.factory.initial"&gt;${initial.context.factory}&lt;/prop&gt;
              &lt;prop key="java.naming.provider.url"&gt;${provider.url}&lt;/prop&gt;
          &lt;/props&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  
  &lt;bean id="jmsQueueConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean" lazy-init="true" depends-on="jndiTemplate"&gt;
      &lt;property name="jndiTemplate"&gt;
          &lt;ref bean="jndiTemplate"/&gt;
      &lt;/property&gt;
      &lt;property name="jndiName"&gt;
          &lt;value&gt;${queue.connection.factory}&lt;/value&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>And here is how my Spring container initialization</p>
  
  <pre><code>    PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer();
      ppc.setProperties(ConfigManager.getProperties());
      AbstractApplicationContext context = new ClassPathXmlApplicationContext("spring-config.xml");
      context.addBeanFactoryPostProcessor(ppc);
      context.refresh();
  </code></pre>
  
  <p>The QueueConnectionFactory initialization throws an exception</p>
  
  <blockquote>
    <p>Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jmsQueueConnectio
    nFactory' defined in class path resource [spring-config.xml]: Invocation of init method failed; nested exception is javax.naming.Com
    municationException [Root exception is java.net.ConnectException: <a href="http://maven.apache.org/ingestionservices-core" rel="noreferrer">http://maven.apache.org/ingestionservices-core</a>: No known valid por
    t for: 'Default[http]:http(http):null:-1:192.168.50.160:-1'; No available router to destination]
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFa
    ctory.java:1412)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFact
    ory.java:519)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactor
    y.java:456)
            at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
            at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222
    )
            at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
            at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
            at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:281)
            at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
            at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:281)
            at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
            at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1075)
            at com.quickplay.ingestionservices.poolmgr.PoolManager.initialize(PoolManager.java:143)
            at com.quickplay.ingestionservices.poolmgr.PoolManager.(PoolManager.java:56)
            at com.quickplay.ingestionservices.poolmgr.PoolManager.main(PoolManager.java:47)</p>
  </blockquote>
  
  <p>It seems like the provider.url property has not been configured correctly. It works if I hard code the provider URL. Can someone point out what is going on? Thanks</p>