相关疑难解决方法(0)

无法自动装配.找不到SimpMessagingTemplate类型的bean

我基本上按照文档中提供的指南在Spring中配置Websockets.

我正在尝试从服务器向客户端发送消息,如 " 从任何地方发送消息 " 一节中所述

在示例之后,您可以自动装配名为SimpMessagingTemplate的类

@Controller
public class GreetingController {

    private SimpMessagingTemplate template;

    @Autowired
    public GreetingController(SimpMessagingTemplate template) {
        this.template = template;
    }

    @RequestMapping(value="/greetings", method=POST)
    public void greet(String greeting) {
        String text = "[" + getTimestamp() + "]:" + greeting;
        this.template.convertAndSend("/topic/greetings", text);
    }

}
Run Code Online (Sandbox Code Playgroud)

但是,我当前的项目找不到bean"SimpMessagingTemplate".(Intellij:'无法自动装配.没有找到SimpMessagingTemplate类型的bean'.

我在互联网上查了几个例子,但是我找不到如何让Spring创建一个SimpMessagingTemplate实例.我怎样才能自动装配它?

编辑:

我决定发送更多背景信息.这是我目前的websocket配置:

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:websocket="http://www.springframework.org/schema/websocket"
       xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/websocket
        http://www.springframework.org/schema/websocket/spring-websocket-4.0.xsd">

        <!-- TODO properties to be read from a properties file -->
        <websocket:message-broker application-destination-prefix="/app">
            <websocket:stomp-endpoint path="/new_session" >
                <websocket:sockjs/>
            </websocket:stomp-endpoint>
            <websocket:simple-broker prefix="/topic"/>
        </websocket:message-broker> …
Run Code Online (Sandbox Code Playgroud)

java stomp javabeans autowired spring-messaging

16
推荐指数
3
解决办法
3万
查看次数

标签 统计

autowired ×1

java ×1

javabeans ×1

spring-messaging ×1

stomp ×1