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

本文主要介绍了如何在Web模块的POM文件中调整打包方式,如何引用并管理第三方jar包,以及在SpringBoot框架下排除内置tomcat并配置WebSocket所需的API。还提到移除ServerEndpointExporter的注释以让Tomcat管理WebSocket服务。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

web模块下的pom文件

1.替换打包方式

    <!--<packaging>jar</packaging>-->
    <packaging>war</packaging>

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>

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>

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>

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();
//    }
//}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值