Spring websocket: how convert easily the Message<?>'s payload to POJO in ChannelInterceptorAdapter

后端 未结 1 1497
深忆病人
深忆病人 2021-01-28 14:06

I have a Spring App working with websocket

I can do the connection and send messages etc.

The @Controller is:

    @MessageMapping(\         


        
相关标签:
1条回答
  • 2021-01-28 14:29

    The AbstractMessageBrokerConfiguration provides this bean:

    @Bean
    public CompositeMessageConverter brokerMessageConverter() {
    

    You need to inject this bean into your MessageChannelInterceptorAdapter and call its fromMessage(Message<?> message, Class<?> targetClass):

    Notification notification = (Notification) this.messageConverter.fromMessage(message, Notification.class);
    
    0 讨论(0)
提交回复
热议问题