Announcement Announcement Module
Collapse
No announcement yet.
PropertyPlaceholderConfigurer and JNDI - get single environment reference from tomcat Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • PropertyPlaceholderConfigurer and JNDI - get single environment reference from tomcat

    Hi
    How is it possible to get a single environment element defined in tomcat's server.xml into a PropertyPlaceholderConfigurer?

    I know there is a lot of stuff about jndi and tomcat etc already written in this forum but i just did not get it run although i think I am quite close.

    Thats what i have till now

    in tomcat's server.xml i define follwing environment entry
    <GlobalNamingResources>
    ....
    <Environment name="jmsBrokerUrl" type="java.lang.String"
    value="tcp://127.0.0.1:61616"/>
    ....
    </GlobalNamingResources>

    And i add the links to context.xml and web.xml in order to be allowed to access the Resource within my web app.

    context.xml

    <ResourceLink global="jmsBrokerUrl" name="jmsBrokerUrl" type="java.lang.String"/>

    web.xml

    <resource-ref>
    <description>JMS Broker Url to use</description>
    <res-ref-name>jmsBrokerUrl</res-ref-name>
    <res-type>java.lang.String</res-type>
    </resource-ref>

    in my webapplication applicationcontext.xml i define a PropertyPlaceholderConfigurer to get jndi property

    <bean id="jndiPropertyConfigurer"
    class="org.springframework.beans.factory.config.Pr opertyPlaceholderConfigurer">
    <property name="properties">
    <bean
    class="org.springframework.jndi.JndiObjectFactoryB ean">
    <property name="jndiName"
    value="java:comp/env/jmsBrokerUrl" />
    <property name="expectedType" value="java.lang.String" />
    </bean>
    </property>
    <property name="ignoreUnresolvablePlaceholders" value="true" />
    </bean>

    And i use jmsBrokerUrl as placeholder reference in my configuration

    <bean id="connectionFactory"
    class="org.apache.activemq.ActiveMQConnectionFacto ry">
    <property name="brokerURL" value="${jmsBrokerUrl}" />
    </bean>

    The lookup seams to work since i get a exception each time i do not provide a valid lookup path for the JndiObjectFactory.
    But i always get the
    2007-07-31 13:55:10,296 ERROR [org.springframework.web.context.ContextLoader] - <Context initialization failed>
    org.springframework.beans.factory.BeanDefinitionSt oreException: Error registering bean with name 'connectionFactory' defined in ServletContext resource [/WEB-INF/messagingConfiguration.xml]: Could not resolve placeholder 'jmsBrokerUrl'
    at org.springframework.beans.factory.config.PropertyP laceholderConfigurer.processProperties(PropertyPla ceholderConfigurer.java:252)
    at org.springframework.beans.factory.config.PropertyR esourceConfigurer.postProcessBeanFactory(PropertyR esourceConfigurer.java:76)
    at org.springframework.context.support.AbstractApplic ationContext.invokeBeanFactoryPostProcessors(Abstr actApplicationContext.java:521)
    at org.springframework.context.support.AbstractApplic ationContext.invokeBeanFactoryPostProcessors(Abstr actApplicationContext.java:495)
    at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:340)
    at org.springframework.web.context.ContextLoader.crea teWebApplicationContext(ContextLoader.java:244)
    at org.springframework.web.context.ContextLoader.init WebApplicationContext(ContextLoader.java:187)
    at org.springframework.web.context.ContextLoaderListe ner.contextInitialized(ContextLoaderListener.java: 49)
    at org.apache.catalina.core.StandardContext.listenerS tart(StandardContext.java:3729)
    at org.apache.catalina.core.StandardContext.start(Sta ndardContext.java:4183)
    at org.apache.catalina.core.ContainerBase.addChildInt ernal(ContainerBase.java:759)
    at org.apache.catalina.core.ContainerBase.addChild(Co ntainerBase.java:739)
    at org.apache.catalina.core.StandardHost.addChild(Sta ndardHost.java:524)
    at org.apache.catalina.startup.HostConfig.deployDirec tory(HostConfig.java:904)
    at org.apache.catalina.startup.HostConfig.deployDirec tories(HostConfig.java:867)
    at org.apache.catalina.startup.HostConfig.deployApps( HostConfig.java:474)
    at org.apache.catalina.startup.HostConfig.start(HostC onfig.java:1112)
    at org.apache.catalina.startup.HostConfig.lifecycleEv ent(HostConfig.java:310)
    at org.apache.catalina.util.LifecycleSupport.fireLife cycleEvent(LifecycleSupport.java:119)
    at org.apache.catalina.core.ContainerBase.start(Conta inerBase.java:1021)
    at org.apache.catalina.core.StandardHost.start(Standa rdHost.java:718)
    at org.apache.catalina.core.ContainerBase.start(Conta inerBase.java:1013)
    at org.apache.catalina.core.StandardEngine.start(Stan dardEngine.java:442)
    at org.apache.catalina.core.StandardService.start(Sta ndardService.java:450)
    at org.apache.catalina.core.StandardServer.start(Stan dardServer.java:709)
    at org.apache.catalina.startup.Catalina.start(Catalin a.java:551)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.catalina.startup.Bootstrap.start(Bootst rap.java:275)
    at org.apache.catalina.startup.Bootstrap.main(Bootstr ap.java:413)

    Exception.

    What do i have to do to get jmsBrokerUrl available at startup ?
    Thanks in advance for your tips and hints.
    Last edited by [email protected]; Jul 31st, 2007, 09:59 AM.
Working...
X