Spring Gateway 遇到异常Unable to start ServletWebServerApplicationContext due to missing ServletWebServe

部署运行你感兴趣的模型镜像

转载的文章,目的是怕突然有一天访问不了

现象

spring gateway 遇到异常,无法启动,异常如下:

14:07:09.901 [main] ERROR o.s.boot.SpringApplication - Application run failed
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:156)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:544)
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747)
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215)
    at cn.devmgr.mall.gateway.GatewayMpApplication.main(GatewayMpApplication.java:20)
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:203)
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:179)
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:153)
    ... 8 common frames omitted

原因

出现这种状况,是由于项目中混入了 spring-webmvc 的包导致的,spring gateway 使用 webflux, 而webflux和webmvc不兼容,就会出现上面的错误。

解决方法

一般不是直接包含了 spring-webmvc,是引入的某个包需要依赖webmvc,找到并排除就好了,但找起来,需要点方法。

用命令 mvn -X package增加一个 -X 参数去打包,会把详细的依赖路径全部都显示出来。例如:

[INFO] <<< spring-boot-maven-plugin:2.2.1.RELEASE:run (default-cli) < test-compile @ gateway-mp-server <<<
[DEBUG] Dependency collection stats: {ConflictMarker.analyzeTime=1, ConflictMarker.markTime=0, ConflictMarker.nodeCount=909, ConflictIdSorter.graphTime=1, ConflictIdSorter.topsortTime=0, ConflictIdSorter.conflictIdCount=230, ConflictIdSorter.conflictIdCycleCount=0, ConflictResolver.totalTime=15, ConflictResolver.conflictItemCount=552, DefaultDependencyCollector.collectTime=27, DefaultDependencyCollector.transformTime=17}
[DEBUG] cn.devmgr.mall:gateway-mp-server:jar:1.0.0
[DEBUG]    cn.devmgr:common-api:jar:1.0.0:compile
[DEBUG]       org.springframework:spring-webmvc:jar:5.2.1.RELEASE:compile
[DEBUG]          org.springframework:spring-beans:jar:5.2.1.RELEASE:compile
[DEBUG]          org.springframework:spring-context:jar:5.2.1.RELEASE:compile
[DEBUG]          org.springframework:spring-expression:jar:5.2.1.RELEASE:compile
[DEBUG]          org.springframework:spring-web:jar:5.2.1.RELEASE:compile
[DEBUG]       org.springframework.security:spring-security-web:jar:5.2.1.RELEASE:compile
[DEBUG]          org.springframework.security:spring-security-core:jar:5.2.1.RELEASE:compile
[DEBUG]       com.auth0:java-jwt:jar:3.9.0:compile
[DEBUG]          com.fasterxml.jackson.core:jackson-databind:jar:2.10.0:compile (version managed from 2.10.0.pr3 by com.fasterxml.jackson:jackson-bom:2.10.0)
[DEBUG]          commons-codec:commons-codec:jar:1.13:compile (version managed from 1.12 by org.springframework.boot:spring-boot-dependencies:2.2.1.RELEASE)
[DEBUG]    org.springframework.cloud:spring-cloud-starter-netflix-eureka-client:jar:2.2.0.RELEASE:compile
[DEBUG]       org.springframework.cloud:spring-cloud-starter:jar:2.2.0.RELEASE:compile
[DEBUG]          org.springframework.cloud:spring-cloud-context:jar:2.2.0.RELEASE:compile
[DEBUG]             org.springframework.security:spring-security-crypto:jar:5.2.1.RELEASE:compile
[DEBUG]          org.springframework.cloud:spring-cloud-commons:jar:2.2.0.RELEASE:compile
[DEBUG]          org.springframework.security:spring-security-rsa:jar:1.0.7.RELEASE:compile
[DEBUG]             org.bouncycastle:bcpkix-jdk15on:jar:1.60:compile
[DEBUG]                org.bouncycastle:bcprov-jdk15on:jar:1.60:compile
[DEBUG]       org.springframework.cloud:spring-cloud-netflix-hystrix:jar:2.2.0.RELEASE:compile
[DEBUG]          org.springframework.boot:spring-boot-starter-aop:jar:2.2.1.RELEASE:compile
[DEBUG]       org.springframework.cloud:spring-cloud-netflix-eureka-client:jar:2.2.0.RELEASE:compile
[DEBUG]       com.netflix.eureka:eureka-client:jar:1.9.13:compile
[DEBUG]          org.codehaus.jettison:jettison:jar:1.3.7:runtime
[DEBUG]             stax:stax-api:jar:1.0.1:runtime
[DEBUG]          com.netflix.netflix-commons:netflix-eventbus:jar:0.3.0:runtime
[DEBUG]             com.netflix.netflix-commons:netflix-infix:jar:0.3.0:runtime
[DEBUG]                commons-jxpath:commons-jxpath:jar:1.3:runtime
[DEBUG]                joda-time:joda-time:jar:2.10.5:runtime (version managed from 2.3 by org.springframework.boot:spring-boot-dependencies:2.2.1.RELEASE)
[DEBUG]                org.antlr:antlr-runtime:jar:3.4:runtime
[DEBUG]                   org.antlr:stringtemplate:jar:3.2.1:runtime
[DEBUG]                   antlr:antlr:jar:2.7.7:runtime
[DEBUG]             org.apache.commons:commons-math:jar:2.2:runtime
[DEBUG]          com.netflix.archaius:archaius-core:jar:0.7.6:compile
[DEBUG]          javax.ws.rs:jsr311-api:jar:1.1.1:runtime
[DEBUG]          com.netflix.servo:servo-core:jar:0.12.21:runtime
[DEBUG]          com.sun.jersey:jersey-core:jar:1.19.1:runtime
[DEBUG]          com.sun.jersey:jersey-client:jar:1.19.1:runtime
[DEBUG]          com.sun.jersey.contribs:jersey-apache-client4:jar:1.19.1:runtime
[DEBUG]          org.apache.httpcomponents:httpclient:jar:4.5.10:compile (version managed from 4.5.3 by org.springframework.boot:spring-boot-dependencies:2.2.1.RELEASE)

在输入里面搜索 webmvc ,找到最上级后,在pom里排除掉即可,例如:

1
2
3
4
5
6
7
8
9
10
11
<dependency>
  <groupId>cn.devmgr</groupId>
  <artifactId>common-api</artifactId>
  <exclusions>
    <exclusion><!-- 这里是排除掉webmvc -->
      <groupId>org.springframework</groupId>
      <artifactId>spring-webmvc</artifactId>
    </exclusion>
  </exclusions>
</dependency>

转载:Spring Gateway 遇到异常Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.无法启动 | GeXiangDong

您可能感兴趣的与本文相关的镜像

Stable-Diffusion-3.5

Stable-Diffusion-3.5

图片生成
Stable-Diffusion

Stable Diffusion 3.5 (SD 3.5) 是由 Stability AI 推出的新一代文本到图像生成模型,相比 3.0 版本,它提升了图像质量、运行速度和硬件效率

2025-11-03 19:56:07.555 WARN 16656 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: 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. 2025-11-03 19:56:07.560 ERROR 16656 --- [ main] o.s.boot.SpringApplication : Application run failed 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:156) ~[spring-boot-2.2.5.RELEASE.jar:2.2.5.RELEASE] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:544) ~[spring-context-5.2.4.RELEASE.jar:5.2.4.RELEASE] at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141) ~[spring-boot-2.2.5.RELEASE.jar:2.2.5.RELEASE] at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747) [spring-boot-2.2.5.RELEASE.jar:2.2.5.RELEASE] at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.2.5.RELEASE.jar:2.2.5.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-2.2.5.RELEASE.jar:2.2.5.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) [spring-boot-2.2.5.RELEASE.jar:2.2.5.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215) [spring-boot-2.2.5.RELEASE.jar:2.2.5.RELEASE] at com.lsl.ymcc.SystemApp.main(SystemApp.java:12) [classes/:na] 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:203) ~[spring-boot-2.2.5.RELEASE.jar:2.2.5.RELEASE] at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:179) ~[spring-boot-2.2.5.RELEASE.jar:2.2.5.RELEASE] at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:153) ~[spring-boot-2.2.5.RELEASE.jar:2.2.5.RELEASE] ... 8 common frames omitted
最新发布
11-04
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值