2

对我来说,这似乎是最简单的 spring 集成示例。我正在尝试向si4demo学习。但是当我运行它时,我得到了这个异常:

线程“主”org.springframework.messaging.MessageDeliveryException 中的异常:调度程序没有频道“application.inbox”的订阅者。嵌套异常是 org.springframework.integration.MessageDispatchingException:调度程序没有订阅者

我哪里错了?定义的流程不会创建对收件箱频道的订阅吗?

import org.springframework.boot.SpringApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.integration.annotation.IntegrationComponentScan;
import org.springframework.integration.annotation.MessagingGateway;
import org.springframework.integration.channel.DirectChannel;
import org.springframework.integration.dsl.IntegrationFlow;
import org.springframework.integration.dsl.IntegrationFlows;
import org.springframework.messaging.MessageChannel;

@Configuration
@ComponentScan
@IntegrationComponentScan
public class App {

    public static void main(String[] args) {

        try (ConfigurableApplicationContext ctx = SpringApplication.run(App.class, args)) {

            final Gateway gateway = ctx.getBean(Gateway.class);
            final String rs = gateway.send("hullo");
            System.out.println(rs);

        }

    }

    private static final String INBOX = "inbox";

    @MessagingGateway(defaultRequestChannel = INBOX)
    public interface Gateway {
        String send(String msg);
    }

    @Bean
    public IntegrationFlow flow() {
        return IntegrationFlows.from(INBOX)
                .transform(p -> "world")
                .get();
    }

    @Bean(name = INBOX)
    public MessageChannel inbox() {
        return new DirectChannel();
    }

}
4

1 回答 1

3

看起来你错过了主要玩家 - @EnableIntegraion

从 4.0 版开始,@EnableIntegration引入了注解,以允许注册 Spring Integration 基础设施 bean(参见 JavaDocs)。当仅使用 Java 和注释配置时需要此注释,例如使用 Spring Boot 和/或 Spring Integration Messaging Annotation 支持以及没有 XML 集成配置的 Spring Integration Java DSL。

http://docs.spring.io/spring-integration/docs/4.3.0.BUILD-SNAPSHOT/reference/html/overview.html#configuration-enable-integration

于 2016-04-04T02:04:01.360 回答