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

        </exclusions>

    </dependency>

移除了webmvc 又报图1的错

接着移除我们的tomcat

    <!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-netflix-eureka-server -->
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        <version>2.2.3.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.springframework</groupId>
                <artifactId>spring-webmvc</artifactId>
            </exclusion>
            <exclusion>
                <artifactId>spring-boot-starter-tomcat</artifactId>
                <groupId>org.springframework.boot</groupId>
            </exclusion>
        </exclusions>

    </dependency>

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/**
            - 

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

总结:

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值