一,報錯內容
當使用gateway的時候,我們可能會在gateway項目中引入一些額外的包,比如webmvc,starter-web等,當然默認是不需要這些的,而且這些放到里面也是會報錯的,一般使用的場景,比如你項目中引入elk,然后加入traceId的時候,就需要使用攔截器等,就會有問題,不過攔截器一般使用gateway的filter就可以了,這個組件會在后面做講解,引用了會有依賴沖突的,會報如下的錯誤
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.
Caused by: org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.

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.
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.JAVA:163)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:577)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:740)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:415)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:303)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1312)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1301)
at com.hanvon.gateway.GatewayApplication.main(GatewayApplication.java:18)
Caused by: org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.getWebServerFactory(ServletWebServerApplicationContext.java:210)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:180)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:160)
... 8 common frames omitted
二,解決方案
找到引用的包里面哪一些是有引用了spring-webmvc 或者 spring-boot-starter-web這個pom文件的,然后將這個進行排除,解決jar沖突的依賴

三,原理
因為gateway在其內部導入了webflux包,但是webmvc和webflux是不能同時出現的,是有沖突的,所以一般做法就是先忽略webmv 包,但是如果必須要使用的話,我們可以進行合理的拆分,將一些功能拆分出來,使用gateway里面中一些GatewayFilterFactory,GatewayPredicate來處理我們需要處理的邏輯