Spring: how to put SimpMessagingTemplate bean in root context?

I am developing a Java webapp with Spring as the main framework (Spring core, Spring mvc, Spring security, Spring data, Spring websocket).

A declaration message-brokerin a Spring context, for example, provides a SimpMessagingTemplatebean context:

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

I need to put this tag in dispatcher-servlet.xml(not applicationContext.xml), otherwise clients will get 404 when they try to connect to websocket (when loading the start page).

However, since this tag, which the SimpMessagingTemplatebean provides (for sending messages to connected clients), is not available in the root context, when the service (scanned by the root context) sends a web socket message, t21> bean cannot be auto-incremented (classic NoSuchBeanDefinitionException).

<websocket:message-broker> applicationContext.xml, dispatcher-servlet.xml applicationContext.xml, , , , SessionRegistry .

, DispatcherServlet , , SessionRegistry bean , ( SO , , , - SessionRegistry bean ).

, ,

<import resource="applicationContext.xml"/>

-servlet.xml, :

  • <websocket:messagebroker>...</> dispatcher-servlet.xml, websocket , autwire SimpMessagingTemplate
  • <websocket:messagebroker>...</> applicationContext.xml, websocket.
  • ( , DispatcherServlet ApplicationContext, SessionRegistry - nope)

, , ? DispatcherServlet beans , , ?

+2
1

. , , SO (. : - -), , .

Autowire SimpMessagingTemplate Controller Scheduled ( dispatcher-servlet, websocket tag), SimpMessagingTemplate ( root context).

(SimpMessagingTemplate ), .

0

All Articles