springboot gateway转发websocket的配置

本文介绍了如何在Spring Boot应用中集成WebSocket,并配置Gateway进行转发。首先,添加了`spring-boot-starter-websocket`依赖。接着,展示了Gateway的`application.yml`配置,包括设置端口、服务发现和路由规则。然后,创建了全局过滤器`CustomFilterConfig`,用于处理跨域请求,特别是针对WebSocket的预检请求进行了特殊处理。通过这些步骤,实现了WebSocket请求从8888端口转发到指定服务。

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

① Spring Boot集成WebSocket的maven依赖:

<dependency>

     <groupId>org.springframework.boot</groupId>

     <artifactId>spring-boot-starter-websocket</artifactId>

</dependency>

②gateway 的application.yml配置

server:
  port: 8888
  
spring:
  application:
    name: gateway
    
  cloud:
    gateway:              
      discovery:
        locator:
          enabled: true
          lowerCaseServiceId: true

      routes:
        - id: service
          uri: lb://SERVICE
          predicates:
            - Path=/test/**
          filters:
            - StripPrefix=1

③gateway全局过滤器配置

@Configuration
public class CustomFilterConfig {
    
    @Bean
    public RequestGlobalFilter customGlobalFilter (){
        return new R

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值