Announcement Announcement Module
Collapse
No announcement yet.
Load tomcat context.xml data into Bean Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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!

  • #2
    I suggest that you figure out what JNDI is.

    Comment


    • #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.

      Comment


      • #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");

        Comment


        • #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 .

          Comment


          • #6
            thanks....please see:

            http://forum.springframework.org/showthread.php?t=59493

            Comment

            Working...
            X