我已经在Spring Boot应用程序中实现了WebSocket机制。
JObject obj = JsonConvert.DeserializeObject("{ 'Name': 'Smith', 'Address': { 'City': 'New York', 'State': 'NY' }, 'Age': 28 }");
var properties = obj.Properties();
foreach (var prop in properties)
{
string key = prop.Name;
object value = prop.Address;
int age = prop.Age;
}
在启动appp期间,WebSocketHandlerMapping检测Websocket连接@Configuration
@EnableWebSocket
public class WebSocketConfiguration implements WebSocketConfigurer {
private String webSockerClientUri;
private WebSocketHandlerRegistry webSocketHandlerRegistry;
private WebSocketHandler webSocketHandler;
@Override
public void registerWebSocketHandlers(WebSocketHandlerRegistry webSocketHandlerRegistry) {
this.webSocketHandlerRegistry = webSocketHandlerRegistry;
this.webSocketHandler = registerWebSocketHandler();
this.webSocketHandlerRegistry.addHandler(this.webSocketHandler, "/test");
}
public WebSocketHandler registerWebSocketHandler(){
return new WebSocketHandler();
}
public WebSocketHandlerRegistry getWebSocketHandlerRegistry() {
return webSocketHandlerRegistry;
}
public WebSocketHandler getWebSocketHandler() {
return webSocketHandler;
}
}
的注册。我想像这样在REST端点中执行相同的操作。
"/test"
Uri已添加到WebSocketHandlerRegistry中,但是WebSocketHandlerMapping机制无法检测到该事实,因为它不是应用程序的启动状态。我该如何解决这个问题?