【问题标题】:Spring Integration Error - Dispatcher has no subscribers for channelSpring 集成错误 - 调度程序没有频道订阅者
【发布时间】:2015-11-02 10:13:07
【问题描述】:

出现错误,

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>

你能帮我解决这个问题吗?

【问题讨论】:

    标签: java spring activemq spring-integration


    【解决方案1】:

    JmsOutboundGateway 和它的 ConnectionFactory 必须声明为 bean。

    即使MyOutboundGateway 作为一个组件被扫描,也不能保证@ServiceActivatormyGatewayChannel 填充正确的端点。

    请修改您的架构并检查您是否真的有&lt;context:component-scan&gt; 来填充@Component 和类似的bean。

    【讨论】:

      猜你喜欢
      • 2013-08-16
      • 2019-10-04
      • 1970-01-01
      • 2013-09-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-12
      • 2019-01-28
      相关资源
      最近更新 更多