【发布时间】:2016-06-30 22:43:12
【问题描述】:
我正在开发一个以 Spring 为主要框架的 Java webapp(主要使用 Spring core、Spring mvc、Spring security、Spring data、Spring websocket)。
像这样在 Spring 上下文中声明消息代理会为上下文提供 SimpMessagingTemplate bean:
<websocket:message-broker>
<websocket:stomp-endpoint path="/stomp">
<websocket:sockjs/>
</websocket:stomp-endpoint>
<websocket:simple-broker prefix="/topic,/queue"/>
</websocket:message-broker>
我必须将此标记放在我的根上下文 (applicationContext.xml) 中,否则在该根上下文中声明的服务无法通过 websocket 向用户发送通知(因为他们需要 SimpMessagingTemplate)。
问题是,如果我将此标签放在根上下文中,客户端在订阅 websocket 时会收到 404。如果我将标签放在 dispatcher-servlet 中,那么根上下文中的服务将无法发送通知,因为它们需要 SimpMessagingTemplate(但它仅在子 dispatcher-servlet 上下文中可用)。
有没有办法将 dispatcher-servlet “绑定”到代理?两次声明 bean 不是正确的解决方案。
这个问题和Spring : how to expose SimpMessagingTemplate bean to root context ?是一样的,但是换个角度看(在根上下文而不是dispatcher-servlet中声明websocket)
【问题讨论】:
标签: java xml spring websocket applicationcontext