Spring : how to expose SimpMessagingTemplate bean to root context ?

后端 未结 1 1198
时光取名叫无心
时光取名叫无心 2021-01-06 13:41

I\'m developing a Java webapp with Spring as the main framework (Spring core, Spring mvc, Spring security, Spring data, Spring websocket are notably used).

Declaring

相关标签:
1条回答
  • 2021-01-06 14:05

    I found a dirty solution. I don't like it, but given the lack of answers on SO (see also : Dispatcher-servlet cannot map to websocket requests ), as well as from current and former colleagues, I had to go forward with the project and implemented a dirty fix.

    The dirty fix is to Autowire the SimpMessagingTemplate in Controller and Scheduled classes (all scanned by the dispatcher-servlet, where the websocket tag is declared), and to pass the SimpMessagingTemplate as a parameter to service methods (declared in the root context).

    This solution is not transparent (the SimpMessagingTemplate should be autowired directly in services ideally) but it definitely fixes the problem.

    0 讨论(0)
提交回复
热议问题