java - 如何将 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
它正在工作。
解决方案
推荐阅读
- laravel - 如何将带有文件的 formData(包括文件和字符串数据)从 Vue 发送到 Laravel API
- angular - 如何以角度提供和注入功能?
- android - 从 Android 启用 Amazon Cognito 中的用户 mfa
- node.js - 如何在where子句中查询jsonb值?
- oracle - PL SQL 我的查询说编译成功,但找不到结果
- symfony - Symfony 5 为什么我不能在我的表单事件监听器中使用 FormsEvents::POST_SUBMIT?
- javascript - Firefox 扩展中的 browser.tabs.executeScript 返回值
- java - 使用“cxf-xjc-plugin”生成的类不能正确导入其他生成的类
- css - Firefox 忽略 DIV 容器的 CSS 高度
- google-sheets - 寻找动态公式 Google 表格