问题
Related with the question autowire simpmessagingtemplate
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 ?
Example:
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");
is not being received by the browser. Everything else works fine.
The beans configuration is:
<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>
Thanks in advance.
回答1:
This question was written due a bug in Intellij IDEA. The response is in Could not autowire. No beans of SimpMessagingTemplate type found
A ticket has been create in JetBrains to solve this problem.
回答2:
try using this configuration
<websocket:message-broker
application-destination-prefix="/app">
<websocket:stomp-endpoint path="/ws">
<websocket:sockjs />
</websocket:stomp-endpoint>
<websocket:simple-broker prefix="/topic/greetings" />
</websocket:message-broker>
insted of
<bean id="executorSC" class="org.springframework.messaging.support.ExecutorSubscribableChannel"/>
来源:https://stackoverflow.com/questions/23026408/how-to-use-executorsubscribablechannel