springboot 加入websocket后,ServerEndpointExporter配置不识别-解决
1.背景
springboot 加入websocket,需要配置ServerEndpointExporter的bean,发现没法识别
2.原因
springboot 内置了tomcat,内置 的tomcat与websocket不兼容,因此需要将 -start-web里的tomcat排除掉即可
3.解决
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
4.bug
tomcat排除掉后,会导致接口的文件传输对象【 MultipartFile 】没有tomcat封装方法,导致以前的简易操作文件方式用不了,只能通过流来处理
4.bug解决
我自己封装了个方法
//有websocket的项目使用这个办法 FileUtil.writeFile(vo.getFile().getInputStream(), aboPath);
//写入文件 public static boolean writeFile(InputStream fis, String tarFilePath) { try { FileOutputStream fos = new FileOutputStream(tarFilePath); byte[] b = new byte[1024]; while ((fis.read(b)) != -1) { fos.write(b);// 写入数据 } fis.close(); fos.close();// 保存数据 } catch (Exception e) { return false; } return true; }
本文来自博客园,作者:岑惜,转载请注明原文链接:https://www.cnblogs.com/c2g5201314/p/16943607.html
响应开源精神相互学习,内容良币驱除劣币
分类:
java
标签:
spring boot
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
· 25岁的心里话