获取错误,
org.springframework.integration.MessageDeliveryException: Dispatcher has no subscribers for channel 'org.springframework.web.context.WebApplicationContext:.myGatewayChannel'.
Caused by: org.springframework.integration.MessageDispatchingException: Dispatcher has no subscribers
代码,
import javax.jms.ConnectionFactory;
import org.apache.activemq.jms.pool.PooledConnectionFactory;
import org.apache.activemq.spring.ActiveMQConnectionFactory;
import org.springframework.context.annotation.Configuration;
import org.springframework.expression.Expression;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.integration.annotation.ServiceActivator;
import org.springframework.integration.jms.JmsOutboundGateway;
@Component
public class MyOutboundGateway
{
@ServiceActivator(inputChannel = "myGatewayChannel")
public JmsOutboundGateway jmsGateway()
{
final JmsOutboundGateway jmsOutboundGateway = new JmsOutboundGateway();
jmsOutboundGateway.setConnectionFactory(this.getConnectionFactory());
final ExpressionParser parser = new SpelExpressionParser();
final Expression requestDestinationExpression = parser.parseExpression("payload.requestQueue");
jmsOutboundGateway.setRequestDestinationExpression(requestDestinationExpression);
final Expression replyDestinationExpression = parser.parseExpression("payload.responseQueue");
jmsOutboundGateway.setReplyDestinationExpression(replyDestinationExpression);
// jmsOutboundGateway.setCorrelationKey("JMSCorrelationID");
jmsOutboundGateway.setExtractRequestPayload(true);
return jmsOutboundGateway;
}
public ConnectionFactory getConnectionFactory()
{
final String brokerUrl = "tcp://localhost:61616";
final ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory();
activeMQConnectionFactory.setBrokerURL(brokerUrl);
final PooledConnectionFactory connectionFactory = new PooledConnectionFactory();
connectionFactory.setCreateConnectionOnStartup(false);
connectionFactory.setMaxConnections(1);
connectionFactory.setMaximumActiveSessionPerConnection(1);
connectionFactory.setIdleTimeout(10);
connectionFactory.setConnectionFactory(activeMQConnectionFactory);
return connectionFactory;
}
}
我的spring-context.xml,
<int:channel id="myGatewayChannel" />
<int:gateway id="myMessageServiceGateway"
service-interface="MyMessageServiceGateway"
default-request-channel="myGatewayChannel" />
我正在使用以下pom依赖,
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-core</artifactId>
<version>3.0.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-jms</artifactId>
<version>3.0.3.RELEASE</version>
</dependency>
请你帮我解决一下。
答案 0 :(得分:0)
必须将JmsOutboundGateway
和ConnectionFactory
声明为bean。
即使将MyOutboundGateway
作为一个组件进行扫描,也无法保证@ServiceActivator
填充myGatewayChannel
的正确端点。
请修改您的体系结构并检查您是否真的有<context:component-scan>
填充@Component
和类似的bean。