我是Spring集成框架的新手。 在运行spring integration websocket sample code的时候,我得到了 的 ' outputChannel'或者' outputChannelName'是必需的 例外。
我错过了什么吗?
以下是我的代码,
@Configuration
@ComponentScan
@EnableAutoConfiguration
@RestController
public class Application {
public static void main(String args[]) throws Throwable {
SpringApplication.run(Application.class, args);
}
@Bean
ServerWebSocketContainer serverWebSocketContainer() {
return new ServerWebSocketContainer("/names").withSockJs();
}
@Bean
MessageHandler webSocketOutboundAdapter() {
return new WebSocketOutboundMessageHandler(serverWebSocketContainer());
}
@Bean(name = "webSocketFlow.input")
MessageChannel requestChannel() {
return new DirectChannel();
}
@Bean
IntegrationFlow webSocketFlow() {
return f -> {
Function<Message, Object> splitter = m -> serverWebSocketContainer().getSessions().keySet().stream()
.map(s -> MessageBuilder.fromMessage(m).setHeader(SimpMessageHeaderAccessor.SESSION_ID_HEADER, s).build()).collect(Collectors.toList());
f.split(Message.class, splitter).channel(c -> c.executor(Executors.newCachedThreadPool())).handle(webSocketOutboundAdapter());
};
}
@RequestMapping("/hi/{name}")
public void send(@PathVariable String name) {
requestChannel().send(MessageBuilder.withPayload(name).build());
}
}
异常堆栈,
java.lang.IllegalStateException: 'outputChannel' or 'outputChannelName' is required
at org.springframework.util.Assert.state(Assert.java:70)
at org.springframework.integration.endpoint.MessageProducerSupport.afterSingletonsInstantiated(MessageProducerSupport.java:153)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:781)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867)
答案 0 :(得分:1)
java.lang.IllegalStateException: 'outputChannel' or 'outputChannelName' is required
at org.springframework.util.Assert.state(Assert.java:70)
at org.springframework.integration.endpoint.MessageProducerSupport.afterSingletonsInstantiated(MessageProducerSupport.java:153)
注意 - MessageProducerSupport
。您的代码没有显示任何类型,因此您只需在我们的应用程序中隐藏一些内容。
我想你可能有类似的东西:
@Bean
public WebSocketInboundChannelAdapter webSocketInboundChannelAdapter() {
...
}
确切地说,这个必须用setOutputChannel()
声明。
或者,如果您将其用作Java DSL的起点 - IntegrationFlows.from(webSocketInboundChannelAdapter())
, - 那么请不要使用@Bean
声明它。随后,框架将为您提供适当的配置和注册。