本文介绍了如何使用ExecutorSubscribableChannel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
与相关的问题
我遇到类ExecutorSubscribableChannel的问题。我希望服务器向浏览器发送异步消息。 如何正确使用ExecutorSubscribableChannel ?
I am having problem the class ExecutorSubscribableChannel. I want the server to send a asynchronous message to the browser. How can I use properly ExecutorSubscribableChannel ?
示例:
public class GreetingController {
@Autowired
private SimpMessagingTemplate template;
public void setTemplate(SimpMessagingTemplate template) {
this.template = template;
}
@MessageMapping("/hello")
@SendTo("/topic/greetings")
public Greeting greeting(HelloMessage message) throws Exception {
Thread.sleep(5000); // simulated delay
this.template.convertAndSend("/topic/greetings", "Hello World");
return new Greeting("Hello, " + message.getName() + "!");
}
}
但是我发送的你好世界文字在行
but the "hello world" text that I am sending in the line
this.template.convertAndSend("/topic/greetings", "Hello World");
。其他一切正常。
bean的配置是:
<bean id="executorSC" class="org.springframework.messaging.support.ExecutorSubscribableChannel"/>
<bean id="template" class="org.springframework.messaging.simp.SimpMessagingTemplate">
<constructor-arg index="0" ref="executorSC"/>
</bean>
提前致谢。
推荐答案
这个问题是由于Intellij IDEA中的一个错误而写的。响应在
This question was written due a bug in Intellij IDEA. The response is in Could not autowire. No beans of SimpMessagingTemplate type found
A 来解决这个问题。
A ticket has been create in JetBrains to solve this problem.
这篇关于如何使用ExecutorSubscribableChannel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!