对我来说,这似乎是最简单的 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();
}
}