-
Aug 29th, 2008, 05:04 AM
#1
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" />
</bean>
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:
<Resource name="jms/TopicConnectionFactory"
type="org.apache.activemq.ActiveMQConnectionFactor y"
description="JMS Connection Factory"
factory="org.apache.activemq.jndi.JNDIReferenceFac tory"
brokerURL="tcp://localhost:61616"
brokerName="myBroker" />
Thanks!
-
Aug 29th, 2008, 05:34 AM
#2
I suggest that you figure out what JNDI is.
-
Aug 29th, 2008, 05:37 AM
#3
I can certainly look into JNDI and what it does, but would you mind pointing me somewhere specific to help me solve my problem?
Thanks.
-
Aug 29th, 2008, 06:41 AM
#4
Ok, thanks for the hint...so I think I got what I needed:
/WEB-INF/applicationContext.xml:
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryB ean">
<property name="jndiName" value="jms/TopicConnectionFactory" />
<property name="resourceRef" value="true" />
</bean>
Java Code:
ActiveMQConnectionFactory af = (ActiveMQConnectionFactory) factory.getBean("dataSource");
-
Aug 29th, 2008, 06:45 AM
#5
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
#6
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules