首页 > 解决方案 > 如何将 websocket 应用程序作为我现有项目 Spring Boot 的一部分添加?

问题描述

我有 Spring Boot 应用程序,我发现了 websocket 聊天的有趣示例。

我试图添加这个:https ://github.com/callicoder/spring-boot-websocket-chat-demo

chat.html但是,如果我尝试从Freemarker模板页面链接到我的页面,它对我不起作用。

例如,在我的main page我有 2 个链接到带有其他模板的其他路径。但我想static html page用原生 javascript 添加链接。我该如何实施?

我试图添加ChatController GetMapping("/chat")(但它不是java逻辑的一部分,因为它的静态代码),所以它对我不起作用。

当我打开那条路径时,我收到:

context with path [] threw exception [Request processing failed; nested exception is java.lang.IllegalStateException: No primary or default constructor found for class org.springframework.messaging.simp.SimpMessageHeaderAccessor] with root cause

没有控制器(GetMapping("/chat"))。:

This application has no explicit mapping for /error, so you are seeing this as a fallback.

如果我反之亦然 - 从模板添加链接websocket app page-Freemarker它正在工作。

标签: javaspringwebsocket

解决方案


推荐阅读