I use Spring-configured jms template with tibco jms library. I get jms connection factory and topic with JNDI and these objects are not null. But when I try to send message or add listener I get this exception:
For listener:
Exception in thread "main" org.springframework.jms.InvalidDestinationException: Can not send into foreign destinations; nested exception is javax.jms.InvalidDestinationException: Can not send into foreign destinations
at org.springframework.jms.support.JmsUtils.convertJmsAccessException(JmsUtils.java:277)
at org.springframework.jms.support.JmsAccessor.convertJmsAccessException(JmsAccessor.java:168)
at org.springframework.jms.core.JmsTemplate.execute(JmsTemplate.java:474)
at org.springframework.jms.core.JmsTemplate.receiveSelected(JmsTemplate.java:700)
at org.springframework.jms.core.JmsTemplate.receive(JmsTemplate.java:682)
at org.springframework.jms.core.JmsTemplate.receive(JmsTemplate.java:674)
For sender:
Exception in thread "main" org.springframework.jms.InvalidDestinationException: Invalid or foreigndestination; nested exception is javax.jms.InvalidDestinationException: Invalid or foreigndestination
at org.springframework.jms.support.JmsUtils.convertJmsAccessException(JmsUtils.java:277)
at org.springframework.jms.support.JmsAccessor.convertJmsAccessException(JmsAccessor.java:168)
at org.springframework.jms.core.JmsTemplate.execute(JmsTemplate.java:474)
at org.springframework.jms.core.JmsTemplate.send(JmsTemplate.java:539)
at org.springframework.jms.core.JmsTemplate.send(JmsTemplate.java:531)
Client app is working with the same topic without problems (so jms server is running). Do you have any ideas? I read about this exception in javadoc, but can't find how to understand the root issue and fix it. Thanks
UPD: JMS-related part of config:
<bean id="JmsFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="${jms.factory}"/>
<property name="proxyInterface" value="javax.jms.TopicConnectionFactory" />
<property name="lookupOnStartup" value="false" />
<property name="jndiEnvironment">
<props>
<prop key="java.naming.provider.url">${jms.namingProvider}</prop>
<prop key="java.naming.factory.initial">${jms.namingFactory}</prop>
<prop key="java.naming.referral">${jms.namingReferra开发者_运维百科l}</prop>
<prop key="java.naming.security.credentials">${jms.securityCredentials}</prop>
<prop key="java.naming.security.principal">${jms.securityPrincipal}</prop>
</props>
</property>
</bean>
<bean id="JmsTopic" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="${jms.topic}"/>
<property name="proxyInterface" value="javax.jms.Topic" />
<property name="lookupOnStartup" value="false" />
<property name="jndiEnvironment">
<props>
<prop key="java.naming.provider.url">${jms.namingProvider}</prop>
<prop key="java.naming.factory.initial">${jms.namingFactory}</prop>
<prop key="java.naming.referral">${jms.namingReferral}</prop>
<prop key="java.naming.security.credentials">${jms.securityCredentials}</prop>
<prop key="java.naming.security.principal">${jms.securityPrincipal}</prop>
</props>
</property>
</bean>
<bean id="UserCredentialsConnectionFactory"
class="org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter">
<property name="targetConnectionFactory">
<ref bean="JmsFactory" />
</property>
<property name="username" value="${jms.user}" />
<property name="password" value="${jms.password}" />
</bean>
<bean id="JmsTemplate"
class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory"
ref="UserCredentialsConnectionFactory" />
<property name="defaultDestination">
<ref bean="JmsTopic"/>
</property>
<property name="pubSubDomain" value="true" />
</bean>
It sounds like you have it configured so that it is attempting to create a destination rather than do a jndi lookup to get the destination that has been defined on the EMS instance.
You need to post your spring config to be sure though.
edit: if you set a destinationname on the JmsTemplate and provide it with a JndiDestinationResolver then it should work
精彩评论