【发布时间】:2021-12-26 12:45:20
【问题描述】:
我有一个 Websocket 端点,我想将其作为标头值接收,而不是字符串而是对象。
这就是我定义 websocket 端点的方式
@MessageMapping("/gather/{resource}")
fun emitGatherEvent(@DestinationVariable resource: String, @Header context: Context) {
LOG.debug("gather endpoint called for client ${context.clientId} and character ${context.characterId} with resource '$resource'")
eventDispatcher.dispatchEvent(Gather(resource), context.characterId)
}
然而 Spring 抛出异常:
org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.lang.String] to type [@org.springframework.messaging.handler.annotation.Header com.barbarus.gameserver.websocket.Context]
我了解这个问题,但我不知道如何为 Context 数据类注册自定义转换器。
知道怎么做吗?
【问题讨论】:
标签: java kotlin spring-mvc websocket spring-websocket