• springcloud 之gateway配置注意事项


    springcloud 之gateway配置注意事项

    1.springcloud 的底层用的是自家的WebFlux 以及netty 但是我们自己用的boot项目是tomcat 和 springmvc 这样会导致我们项目编译都不会通过
    如果直接导入了web starter 会提示找到了mvc idea 不抽风的话会提示移除不恰当的springmvc
    在这里插入图片描述
    图1
    这里提示我们的tomcat已经启动成功 但是报错:
    java.lang.ClassCastException: org.springframework.core.io.buffer.DefaultDataBufferFactory cannot be cast to org.springframework.core.io.buffer.NettyDataBufferFactory
    at org.springframework.cloud.gateway.filter.NettyWriteResponseFilter.lambda$filter 1 ( N e t t y W r i t e R e s p o n s e F i l t e r . j a v a : 82 ) [ s p r i n g c l o u d g a t e w a y c o r e 2.2.1. R E L E A S E . j a r : 2.2.1. R E L E A S E ] S u p p r e s s e d : r e a c t o r . c o r e . p u b l i s h e r . F l u x O n A s s e m b l y 1(NettyWriteResponseFilter.java:82) ~[spring-cloud-gateway-core-2.2.1.RELEASE.jar:2.2.1.RELEASE] Suppressed: reactor.core.publisher.FluxOnAssembly 1(NettyWriteResponseFilter.java:82)[springcloudgatewaycore2.2.1.RELEASE.jar:2.2.1.RELEASE]Suppressed:reactor.core.publisher.FluxOnAssemblyOnAssemblyException:
    Error has been observed at the following site(s):
    |_ checkpoint org.springframework.cloud.gateway.filter.WeightCalculatorWebFilter [DefaultWebFilterChain]
    |_ checkpoint HTTP GET “/orderPay/order/1” [ExceptionHandlingWebHandler]

    这时我已经排除了本modul的webstarter 但是还是提示要求我移除webstarter
    好郁闷
    好吧 我自己来exclusion 好吧/(ㄒoㄒ)/~~

    org.springframework.cloud
    spring-cloud-starter-netflix-eureka-client
    2.2.3.RELEASE

    org.springframework.boot
    spring-boot-starter-web

    org.springframework
    spring-webmvc

            
    
        
    
    • 1
    • 2
    • 3

    移除了webmvc 又报图1的错

    接着移除我们的tomcat

        
        
            org.springframework.cloud
            spring-cloud-starter-netflix-eureka-client
            2.2.3.RELEASE
        
        
            org.springframework.boot
            spring-boot-starter-web
            
                
                    org.springframework
                    spring-webmvc
                
                
                    spring-boot-starter-tomcat
                    org.springframework.boot
                
            
    
        
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21

    yml配置如下

    spring:
      main:
        allow-bean-definition-overriding: true
      application:
        name: gateway9527
      cloud:
        discovery:
          locator:
            enabled: true   #开启从注册中心动态创建路由的功能,利用微服务名进行路由
        gateway:
          routes:
            - id: before_route
              uri: lb://PRODUCT
              predicates:
                - Path=/orderPay/order/**
                - 
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16

    当当当 !!
    在这里插入图片描述
    看到提示netty启动成功我们的gateway整合cloud完美成功啦 接下来就是一些配置啦

    总结:

    cloud整合gateway的时候一定要exclusion webstarter 如果移除了还是不行 那我们就自己手动exclusion tomcat 和mvc
    切记!切记!切记!

  • 相关阅读:
    [2023 java毕业设计源码]基于SpringBoot的在线交友系统包运行成功]
    python 小案例76
    移动端测试理论知识
    算法训练 第三周
    docker容器
    4k壁纸爬100页 python
    JAVA面试之容器
    MySQL中BETWEEN AND(范围查询)
    算法体系版-左程云-笔记(1)
    虹科分享 | 网络仿真器 | 预测云中对象存储系统的实际性能
  • 原文地址:https://blog.csdn.net/m0_54850467/article/details/126616215