Spring Web套接字 - 找不到元素[message-broker]的BeanDefinitionParser

时间:2016-07-04 13:07:11

标签: spring spring-mvc spring-websocket

我试图在Spring网络应用中添加spring-websocket依赖项。

我在pom.xml中添加了这个依赖项:

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-websocket</artifactId>
    <version>4.2.4</version>
</dependency>

我已经为@EnableWebSocketMessageBroker创建了一个等效的XML配置,如下所示:

http://docs.spring.io/spring/docs/current/spring-framework-reference/html/websocket.html#websocket-stomp-enable

所以,我有这个spring-socket-context.xml:

<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.xsd">

    <websocket:message-broker application-destination-prefix="/app">
        <websocket:stomp-endpoint path="/myPath">
            <websocket:sockjs/>
        </websocket:stomp-endpoint>
        <websocket:simple-broker prefix="/topic, /queue"/>
    </websocket:message-broker>

</beans>

当我启动网络应用时,我立即出现此错误:

[ERROR] 2016-07-04 14:52:11,381 [] []  org.springframework.web.context.ContextLoader initWebApplicationContext - Context initialization failed
org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Cannot locate BeanDefinitionParser for element [message-broker]

如何解决此错误?

感谢。

1 个答案:

答案 0 :(得分:0)

我遇到与您相同的错误。

事实证明,您需要在类路径中使用 spring-messaging jar才能在xml中使用 websocket:message-broker

错误消息根本没用;