• 若依前后端分离,ruoyi-vue jar包更改成war包发布 Websocket 配置


    web模块下的pom文件

    1.替换打包方式

        <!--<packaging>jar</packaging>-->
        <packaging>war</packaging>
    
    • 1
    • 2

    2.如果引用第三方jar包,打入webResources(选做)

    <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-war-plugin</artifactId>
                    <version>3.1.0</version>
                    <configuration>
                        <webResources>
                            <webResource>
                                <directory>${pom.basedir}/src/main/resources/lib/</directory>
                                <targetPath>WEB-INF/lib/</targetPath>
                                <includes>
                                    <include>**/*.jar</include>
                                </includes>
                            </webResource>
                        </webResources>
                        <failOnMissingWebXml>false</failOnMissingWebXml>
                        <warName>${project.artifactId}</warName>
                    </configuration>
                </plugin>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18

    framework下的pom文件

    3.排除jar包中的内置tomcat

            <!-- SpringBoot Web容器 -->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
                <!--            war包发布        -->
                <!--            排除jar包中的内置tomcat-->
                <exclusions>
                    <exclusion>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-starter-tomcat</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13

    4.WebSocket需要的API

            <!-- 排除jar包中的内置tomcat,WebSocket需要的API-->
            <dependency>
                <groupId>javax.websocket</groupId>
                <artifactId>javax.websocket-api</artifactId>
                <version>1.1</version>
                <scope>provided</scope>
            </dependency>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    ServerEndpointExporter交由Tomcat管理

    注释ServerEndpointExporter

    package com.huida.framework.websocket;
    
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
    import org.springframework.web.socket.server.standard.ServerEndpointExporter;
    
    /**
     * websocket 配置
     *
     * @author huida
     */
    //@Configuration
    //public class WebSocketConfig
    //{
    //    @Bean
    //    public ServerEndpointExporter serverEndpointExporter()
    //    {
    //        return new ServerEndpointExporter();
    //    }
    //}
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
  • 相关阅读:
    设计一个简单HTML爵士音乐网页(HTML+CSS)
    【Git CMD】Git上传本地代码到远程仓库(6步到位)
    【系统分析师之路】第五章 复盘软件工程(软件过程改进)
    1124:矩阵加法
    github数据怎么Python爬取
    Vue学习笔记(六):监视属性
    2023-09-12 LeetCode每日一题(课程表 IV)
    mysql-8.0.31-glibc2.12-x86_64.tar.xz 离线安装mysql8.0
    康托展开与逆康托展开
    写作技巧网站或工具
  • 原文地址:https://blog.csdn.net/qq_43751489/article/details/136686139