tags:

views:

78

answers:

1

Hi,

My project requires the Initial Context Factory and the provider URL to be loaded from a properties file. Here is my Spring configuration

<bean id="jndiTemplate" class="org.springframework.jndi.JndiTemplate" lazy-init="true">
    <property name="environment">
        <props>
            <prop key="java.naming.factory.initial">${initial.context.factory}</prop>
            <prop key="java.naming.provider.url">${provider.url}</prop>
        </props>
    </property>
</bean>

<bean id="jmsQueueConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean" lazy-init="true" depends-on="jndiTemplate">
    <property name="jndiTemplate">
        <ref bean="jndiTemplate"/>
    </property>
    <property name="jndiName">
        <value>${queue.connection.factory}</value>
    </property>
</bean>

And here is how my Spring container initialization

    PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer();
    ppc.setProperties(ConfigManager.getProperties());
    AbstractApplicationContext context = new ClassPathXmlApplicationContext("spring-config.xml");
    context.addBeanFactoryPostProcessor(ppc);
    context.refresh();

The QueueConnectionFactory initialization throws an exception

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: http://maven.apache.org/ingestionservices-core: 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)

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

+1  A: 

modify your existing config.xml file

 <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location">
        <value>classpath:project.properties</value>
    </property>
</bean>


<bean id="jndiTemplate" class="org.springframework.jndi.JndiTemplate" lazy-init="true">
    <property name="environment">
        <props>
            <prop key="java.naming.factory.initial">${initial.context.factory}</prop>
            <prop key="java.naming.provider.url">${provider.url}</prop>
        </props>
    </property>
</bean>

<bean id="jmsQueueConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean" lazy-init="true" depends-on="jndiTemplate">
    <property name="jndiTemplate">
        <ref bean="jndiTemplate"/>
    </property>
    <property name="jndiName">
        <value>${queue.connection.factory}</value>
    </property>
</bean>

create properties file "project.properties", place in class path

# jndiTemplate Info
queue.connection.factory="value..."
provider.url="value..."
initial.context.factory="value..."
Aaron Saunders