Aug 29th, 2008, 05:04 AM
Load tomcat context.xml data into Bean
I have some "Resource" tags in my context.xml (in tomcat, META-INF/context.xml). In my code I need to use some of the values stored in context.xml. I could duplicate these values in my applicationContext.xml (my spring configuration), for example:
<bean id="fooConfig" class="com.acme.FooConfig">
<property name="resourceName" value="blah" />
<property name="brokerUrl" value="http://localhost:1234" />
But I'd rather use the values that are already defined in context.xml rather than duplicating the information.
Is there some way of using information from my META-INF/context.xml (tomcat config) in my Spring configuration?
An example XML tag in my META-INF/context.xml that I need to get properties from is:
description="JMS Connection Factory"
Aug 29th, 2008, 05:34 AM
I suggest that you figure out what JNDI is.
Aug 29th, 2008, 05:37 AM
I can certainly look into JNDI and what it does, but would you mind pointing me somewhere specific to help me solve my problem?
Aug 29th, 2008, 06:41 AM
Ok, thanks for the hint...so I think I got what I needed:
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryB ean">
<property name="jndiName" value="jms/TopicConnectionFactory" />
<property name="resourceRef" value="true" />
ActiveMQConnectionFactory af = (ActiveMQConnectionFactory) factory.getBean("dataSource");
Aug 29th, 2008, 06:45 AM
Please use [ code][/code ] tags when posting code.
You are using spring so don't use the getBean stuff, inject your dependencies.
All the resources in Tomcat are JNDI resources which you can retrieve by their respective names. You figured that out already .
Aug 29th, 2008, 06:47 AM