views:

299

answers:

1

Hi. Now I have java code which starts tibco jms subscription with several steps:

Properties props = new Properties();
        props.put("java.naming.provider.url", namingProvider);
        props.put("java.naming.factory.initial", namingFactory);
        props.put("java.naming.referral", namingReferral);
        props.put("java.naming.security.credentials", securityCredentials);
        props.put("java.naming.security.principal", securityPrincipal);

        context = new InitialContext(props);
        TopicConnectionFactory tfactory = (TopicConnectionFactory) context
                .lookup(url + topic + ":tcf");

        topicConnection = tfactory.createTopicConnection(user, password);
        topicConnection.setExceptionListener(exceptionListener);
        topicSession = topicConnection.createTopicSession(false,
                Session.AUTO_ACKNOWLEDGE);      
        subscriber = topicSession.createSubscriber(
                (Topic) context.lookup(url + topic + ":topic"),
                SELECTOR, true); 
        subscriber.setMessageListener(messageListener);
        topicConnection.start();

I want to use Spring for initialization, but I can't find how to configure jms in spring using initial context. Can you help me with it? Thanks!

A: 

You can try something like this to get TopicConnectionFactory:

<bean id="tfactory" class="org.springframework.jndi.JndiObjectFactoryBean">
  <property name="jndiName" value="url/topic:tcf"/>
  <property name="jndiEnvironment">
    <props>
      <prop key="java.naming.provider.url">...</prop>
      <prop key="java.naming.factory.initial">...</prop>
      <prop key="java.naming.referral">...</prop>
      <prop key="java.naming.security.credentials">...</prop>
      <prop key="java.naming.security.principal">...</prop>
    </props>
  </property>
</bean>
Eugene Kuleshov