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
切记!切记!切记!