spring-cloud-gateway启动踩坑及解决
⽬录
spring-cloud-gateway启动踩坑
1、webflux与mvc不兼容
2、webflux使⽤netty作为容器
3、后来实验了下
很坑得springcloudgateway异常
spring-cloud-gateway启动踩坑
本⼈使⽤的版本是2.1.2,以下只记录⼏个⼩问题,但确实实实在在的把个⼈恶⼼的要死要活的不到办法,⼏经挣扎,最终解决。
更可恨的是开发的过程中,没有出现异常,后来由于项⽬组其它⼈加了依赖,不知不觉对项⽬的兼容造成了英雄,真的是被撞的头破⾎流,才到原因
1、webflux与mvc不兼容
如类路径中引⽤了webmvc会导致项⽬启动不起来
异常1
t.ApplicationContextException: Unable to start web server; nested exception is
t.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing
ServletWebServerFactory bean.
异常2
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type
'onvert.ConversionService' available: expected at least 1 bean which qualifies as autowire candidate.
Dependency annotations: {@org.springframework.beans.factory.annotation.Qualifier(value=webFluxConversionService)}
springcloud难学吗解决办法,到依赖webmvc的jar包,将webmvc排除即可,如
<dependency>
<groupId>${upId}</groupId>
<artifactId>core</artifactId>
<version>${project.version}</version>
<exclusions>
<!--
1. webflux与webmvc不兼容,否则会项⽬启动不起来
-->
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
</exclusion>
</dependency>
2、webflux使⽤netty作为容器
不能使⽤tomcat,表现形式为⽹关⼯作转发正常,⽬标服务返回数据也正常,但是⽹关会⽆法解析返回的数据并最终由⽹关将数据返回给客户端
java.lang.ClassCastException: io.buffer.DefaultDataBufferFactory cannot be cast to
io.buffer.NettyDataBufferFactory
解决办法
到将tomcat依赖进来的jar包,然后排除即可。需要注意的是,要看清楚⾃⼰项⽬依赖的tomcat具体
的maven坐标。
然后排除即可
<dependency>
<groupId>${upId}</groupId>
<artifactId>core</artifactId>
<version>${project.version}</version>
<exclusions>
<!--
1. webflux与webmvc不兼容,否则会项⽬启动不起来
2. webflux使⽤Netty作为容器,如果使⽤tomcat,接⼝转发正常,但是会导致服务间的数据⽆法解析
java.lang.ClassCastException: io.buffer.DefaultDataBufferFactory
cannot be cast to io.buffer.NettyDataBufferFactory -->
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework.bootk</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
<exclusion>
<groupId>at.embed</groupId>
<artifactId>tomcat-embed-core</artifactId>
</exclusion>
<exclusion>
<groupId>at.embed</groupId>
<artifactId>tomcat-embed-el</artifactId>
</exclusion>
<exclusion>
<groupId>at.embed</groupId>
<artifactId>tomcat-embed-websocket</artifactId>
</exclusion>
</exclusions>
</dependency>
3、后来实验了下
关于1webflux和mvc不兼容项⽬启动不起来的异常,如果项⽬中存在了tomcat的⽤来,则抛出的异常是
t.ApplicationContextException: Unable to start web server; nested exception is
t.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing
ServletWebServerFactory bean.
⽽如果没有依赖tomcat则抛出的异常是
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type
'onvert.ConversionService' available: expected at least 1 bean which qualifies as autowire candidate.
Dependency annotations: {@org.springframework.beans.factory.annotation.Qualifier(value=webFluxConversionService)}
很坑得spring cloud gateway 异常
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type
'onvert.ConversionService' available: expected at least 1 bean which qualifies as autowire candidate.
Dependency annotations: {@org.springframework.beans.factory.annotation.Qualifier(value=webFluxConversionService)}
at
org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:1655) ~[spring-beans-5.1.7.RELEASE.jar:5.1.7.RELEASE]
at
org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1214) ~[spring-beans-5.1.7.RELEASE.jar:5.1.7.RELEASE]
at
org.springframework.beans.factory.solveDependency(DefaultListableBeanFactory.java:1168) ~ [spring-beans-5.1.7.RELEASE.jar:5.1.7.RELEASE]
at org.springframework.beans.factory.solveAutowiredArgument(ConstructorResolver.java:857) ~
[spring-beans-5.1.7.RELEASE.jar:5.1.7.RELEASE]
at org.springframework.beans.factory.ateArgumentArray(ConstructorResolver.java:760) ~[spring-
beans-5.1.7.RELEASE.jar:5.1.7.RELEASE]
... 101 common frames omitted
这个异常是因为spring cloud gateway 是webflux 项⽬,引了含有web-starter得项⽬就会出现冲突。因为Hystrix-dashboard中含有web-starter,所
以出现冲突。
以上为个⼈经验,希望能给⼤家⼀个参考,也希望⼤家多多⽀持。

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。