使用Spring3 + JNDI连接到EMS JMS队列

时间:2011-07-20 16:05:14

标签: spring jms tibco ems

我遇到一些问题,建立了与Tibco EMS JMS队列的连接(和读取)。

<beans>
    <bean id="jndiTemplate" class="org.springframework.jndi.JndiTemplate">
        <property name="environment">
            <props>
                <prop key="java.naming.factory.initial">com.tibco.tibjms.naming.TibjmsInitialContextFactory</prop>
                <prop key="java.naming.provider.url">tcp://ems-dit-am-uat-1.app.xxx.net:30055</prop>
            </props>
        </property>
    </bean>

    <bean id="jmsConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
        <property name="jndiTemplate" ref="jndiTemplate" /> <property name="jndiName"
        value="DRDRFIQueueConnectionFactory" /> </bean>

    <bean id="jmsDestinationResolver"
        class="org.springframework.jms.support.destination.JndiDestinationResolver">
        <property name="jndiTemplate" ref="jndiTemplate" />
        <property name="cache" value="true" />
    </bean>

    <bean id="destination" class="org.springframework.jndi.JndiObjectFactoryBean">
        <property name="jndiTemplate" ref="jndiTemplate" />
        <property name="jndiName" value="Q.NY.DERIV.DRD.RFI" />
    </bean>

    <bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
        <property name="connectionFactory" ref="jmsConnectionFactory" />
        <property name="destinationResolver" ref="jmsDestinationResolver" />
        <property name="defaultDestination" ref="destination" />
    </bean>


    <bean id="jmsReceiver" class="com.csfb.fao.rds.rfi.application.DRDReceiverTst">
        <property name="jmsTemplate">
            <ref bean="jmsTemplate" />
        </property>
    </bean>

</beans>

我得到的例外是:

  

javax.naming.AuthenticationException:不允许:名称无效或   password [根异常是javax.jms.JMSSecurityException:无效   名称或密码]   com.tibco.tibjms.naming.TibjmsContext.lookup(TibjmsContext.java:668)     在   com.tibco.tibjms.naming.TibjmsContext.lookup(TibjmsContext.java:489)     在javax.naming.InitialContext.lookup(InitialContext.java:392)at   org.springframework.jndi.JndiTemplate $ 1.doInContext(JndiTemplate.java:154)     在   org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:87)     在   org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:152)     在   org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:178)     在   org.springframework.jndi.JndiLocatorSupport.lookup(JndiLocatorSupport.java:95)     在   org.springframework.jndi.JndiObjectLocator.lookup(JndiObjectLocator.java:105)     在   org.springframework.jndi.JndiObjectFactoryBean.lookupWithFallback(JndiObjectFactoryBean.java:201)     在   org.springframework.jndi.JndiObjectFactoryBean.afterPropertiesSet(JndiObjectFactoryBean.java:187)     在   org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477)     在   org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417)     ......还有12个

我给出的唯一用户/密码是JMS队列本身 - 我在哪里设置?

由于 克里斯

3 个答案:

答案 0 :(得分:2)

得到它 - 需要将连接工厂包装在UserCredentialsConnectionFactory中:

<bean id="authenticationConnectionFactory"
    class="org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter">
    <property name="targetConnectionFactory" ref="jmsConnectionFactory" />
    <property name="username" value="yyyyy" />
    <property name="password" value="xxxx" />
</bean>

<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
    <property name="connectionFactory" ref="authenticationConnectionFactory" />
    <property name="destinationResolver" ref="jmsDestinationResolver" />
    <property name="defaultDestination" ref="destination" />

答案 1 :(得分:2)

我有一些类似的问题,解决方案是添加(除了这个问题的解决方案)

<prop key="java.naming.security.principal">username</prop>
<prop key="java.naming.security.credentials">password</prop>

jndiTemplate bean配置

答案 2 :(得分:1)

我对EMS没有任何经验,但通常在连接工厂上设置用户和密码,因此您需要在JNDI提供的对象上配置它。