国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

您的位置:首頁技術文章
文章詳情頁

spring-cloud-gateway啟動踩坑及解決

瀏覽:3日期:2023-12-14 08:46:57
目錄spring-cloud-gateway啟動踩坑1、webflux與mvc不兼容2、webflux使用netty作為容器3、后來實驗了下很坑得springcloudgateway異常spring-cloud-gateway啟動踩坑

本人使用的版本是2.1.2,以下只記錄幾個小問題,但確實實實在在的把個人惡心的要死要活的找不到辦法,幾經掙扎,最終解決。

更可恨的是開發(fā)的過程中,沒有出現(xiàn)異常,后來由于項目組其它人加了依賴,不知不覺對項目的兼容造成了英雄,真的是被撞的頭破血流,才找到原因

1、webflux與mvc不兼容

如類路徑中引用了webmvc會導致項目啟動不起來

異常1

org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.

異常2

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type ’org.springframework.core.convert.ConversionService’ available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Qualifier(value=webFluxConversionService)}

解決辦法,找到依賴webmvc的jar包,將webmvc排除即可,如

<dependency> <groupId>${project.groupId}</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,表現(xiàn)形式為網關工作轉發(fā)正常,目標服務返回數(shù)據也正常,但是網關會無法解析返回的數(shù)據并最終由網關將數(shù)據返回給客戶端

java.lang.ClassCastException: org.springframework.core.io.buffer.DefaultDataBufferFactory cannot be cast to org.springframework.core.io.buffer.NettyDataBufferFactory

解決辦法

https://github.com/spring-cloud/spring-cloud-gateway/issues/145

找到將tomcat依賴進來的jar包,然后排除即可。需要注意的是,要看清楚自己項目依賴的tomcat具體的maven坐標。

spring-cloud-gateway啟動踩坑及解決

然后排除即可

<dependency> <groupId>${project.groupId}</groupId> <artifactId>core</artifactId> <version>${project.version}</version> <exclusions> <!-- 1. webflux與webmvc不兼容,否則會項目啟動不起來 2. webflux使用Netty作為容器,如果使用tomcat,接口轉發(fā)正常,但是會導致服務間的數(shù)據無法解析 java.lang.ClassCastException: org.springframework.core.io.buffer.DefaultDataBufferFactory cannot be cast to org.springframework.core.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>org.apache.tomcat.embed</groupId> <artifactId>tomcat-embed-core</artifactId> </exclusion> <exclusion> <groupId>org.apache.tomcat.embed</groupId> <artifactId>tomcat-embed-el</artifactId> </exclusion> <exclusion> <groupId>org.apache.tomcat.embed</groupId> <artifactId>tomcat-embed-websocket</artifactId> </exclusion> </exclusions></dependency>3、后來實驗了下

關于1webflux和mvc不兼容項目啟動不起來的異常,如果項目中存在了tomcat的用來,則拋出的異常是

org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.

而如果沒有依賴tomcat則拋出的異常是

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type ’org.springframework.core.convert.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 ’org.springframework.core.convert.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.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1168) ~[spring-beans-5.1.7.RELEASE.jar:5.1.7.RELEASE]at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:857) ~[spring-beans-5.1.7.RELEASE.jar:5.1.7.RELEASE]at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:760) ~[spring-beans-5.1.7.RELEASE.jar:5.1.7.RELEASE]... 101 common frames omitted

這個異常是因為spring cloud gateway 是webflux 項目,引了含有web-starter得項目就會出現(xiàn)沖突。因為Hystrix-dashboard中含有web-starter,所以出現(xiàn)沖突。

以上為個人經驗,希望能給大家一個參考,也希望大家多多支持好吧啦網。

標簽: Spring
相關文章:
主站蜘蛛池模板: 日本一道免费一区二区三区 | 色视频在线免费 | 91精品欧美一区二区综合在线 | 亚洲另类视频在线观看 | 无套内谢孕妇毛片免费看 | 国产成人精品视频一区 | 在线国产一区二区三区 | 456亚洲视频 | 在线观看欧美一区 | 国产精品视频久久 | 亚洲理论在线观看 | 国产在线观看xxxx免费 | 国内精品视频九九九九 | 国产在线精品一区二区夜色 | 国产二区三区毛片 | 亚洲成网站 | 国产精品秦先生手机在线 | 日韩欧美理论片 | 国产高清第一页 | 国产高清视频免费观看 | 欧美一区二三区 | 在线不卡一区二区三区日韩 | 在线 | 一区二区三区 | 美女网站色免费 | 自拍视频在线 | 国产不卡影院 | 欧美毛片aaa激情 | 伊人一级 | 免费亚洲成人 | 曰本女同互慰高清在线观看 | 日韩三级在线观看 | 九草视频在线 | 国产成人精品福利站 | 国产一区2区| 一本久道久久综合婷婷五 | gdcm01果冻传媒 | 国产亚洲精品国产一区 | 日本欧美一级二级三级不卡 | 日韩精品网 | 波多野结衣一区二区 | 国产亚洲精品久久久久久久久激情 |