其他分享
首页 > 其他分享> > 使用Spring3 JNDI连接到EMS JMS队列

使用Spring3 JNDI连接到EMS JMS队列

作者:互联网

我遇到了一些问题,建立了与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: Not permitted: invalid name or
password [Root exception is javax.jms.JMSSecurityException: invalid
name or password] at
com.tibco.tibjms.naming.TibjmsContext.lookup(TibjmsContext.java:668)
at
com.tibco.tibjms.naming.TibjmsContext.lookup(TibjmsContext.java:489)
at javax.naming.InitialContext.lookup(InitialContext.java:392) at
org.springframework.jndi.JndiTemplate$1.doInContext(JndiTemplate.java:154)
at
org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:87)
at
org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:152)
at
org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:178)
at
org.springframework.jndi.JndiLocatorSupport.lookup(JndiLocatorSupport.java:95)
at
org.springframework.jndi.JndiObjectLocator.lookup(JndiObjectLocator.java:105)
at
org.springframework.jndi.JndiObjectFactoryBean.lookupWithFallback(JndiObjectFactoryBean.java:201)
at
org.springframework.jndi.JndiObjectFactoryBean.afterPropertiesSet(JndiObjectFactoryBean.java:187)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417)
… 12 more

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

谢谢
克里斯

解决方法:

得到它 – 需要将连接工厂包装在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" />

标签:tibco,spring,jms,ems
来源: https://codeday.me/bug/20190903/1795764.html