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;
    }
复制代码

 

posted @   岑惜  阅读(3403)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
· 25岁的心里话
点击右上角即可分享
微信分享提示