org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplication...

先说结论,启动项目时遇到以下报错:org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.

,解决方法有两个(我是使用第一种方法解决的):

  • 引入web依赖

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
  • 设置web-application-type:

    spring:
      main:
        web-application-type: none

解决流程:

启动项目的时候遇到了如下报错:

2019-07-10 00:20:14.844 ERROR [,,,] 5332 --- [           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:157) ~[spring-boot-2.1.1.RELEASE.jar:2.1.1.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:540) ~[spring-context-5.1.3.RELEASE.jar:5.1.3.RELEASE]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142) ~[spring-boot-2.1.1.RELEASE.jar:2.1.1.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775) [spring-boot-2.1.1.RELEASE.jar:2.1.1.RELEASE]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.1.1.RELEASE.jar:2.1.1.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:316) [spring-boot-2.1.1.RELEASE.jar:2.1.1.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260) [spring-boot-2.1.1.RELEASE.jar:2.1.1.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248) [spring-boot-2.1.1.RELEASE.jar:2.1.1.RELEASE]
    at com.smartit.spcloud.server.cms.ServerCmsApplication.main(ServerCmsApplication.java:21) [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:206) ~[spring-boot-2.1.1.RELEASE.jar:2.1.1.RELEASE]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:180) ~[spring-boot-2.1.1.RELEASE.jar:2.1.1.RELEASE]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:154) ~[spring-boot-2.1.1.RELEASE.jar:2.1.1.RELEASE]
    ... 8 common frames omitted

Disconnected from the target VM, address: '127.0.0.1:7553', transport: 'socket'

Process finished with exit code 1
  1. 往常遇到这种报错,一般都是端口被占用,但是这次往上翻了翻没看到端口报错日志,于是google了一下,看到stackoverflow上有人说解决方法是在application.yml里添加一段配置(原文链接:

    spring:
      main:
        web-application-type: none
  2. 添加启动后倒是不再报刚才的错误,但是刚启动注册到eureka,又会自动关闭,日志如下:

    15144 --- [           main] c.s.s.server    : Started  in 14.068 seconds (JVM running for 15.815)
    2019-07-10 00:40:40.488  INFO ,,,] 15144 --- [      Thread-35] o.s.c.n.e.s.EurekaServiceRegistry        : Unregistering application with eureka with status DOWN
    2019-07-10 00:40:40.488  WARN [,,,] 15144 --- [      Thread-35] com.netflix.discovery.DiscoveryClient    : Saw local status change event StatusChangeEvent [timestamp=1562690440488, current=DOWN, previous=UP]
    2019-07-10 00:40:40.497  INFO [,,,] 15144 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient    : DiscoveryClient_/192.168.0.106:8888 - registration status: 204
    2019-07-10 00:40:40.498  INFO [,,,] 15144 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient    : DiscoveryClient/192.168.0.106:8888: registering service...
    2019-07-10 00:40:40.502  INFO [,,,] 15144 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient    : DiscoveryClient_SE/192.168.0.106:8888 - registration status: 204
    2019-07-10 00:40:40.821  WARN [,,,] 15144 --- [ender@10545d02}] s.c.a.AnnotationConfigApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'eurekaRibbonClientConfiguration': Unsatisfied dependency expressed through field 'eurekaConfig'; nested exception is org.springframework.beans.factory.BeanCreationNotAllowedException: Error creating bean with name 'eurekaInstanceConfigBean': Singleton bean creation not allowed while singletons of this factory are in destruction (Do not request a bean from a BeanFactory in a destroy method implementation!)
    2019-07-10 00:40:40.862  INFO [,,,] 15144 --- [      Thread-35] com.alibaba.druid.pool.DruidDataSource   : {dataSource-1} closed
    2019-07-10 00:40:40.863  INFO [,,,] 15144 --- [      Thread-35] com.netflix.discovery.DiscoveryClient    : Shutting down DiscoveryClient ...
    2019-07-10 00:40:43.864  INFO [,,,] 15144 --- [      Thread-35] com.netflix.discovery.DiscoveryClient    : Unregistering ...
    2019-07-10 00:40:43.877  INFO [,,,] 15144 --- [      Thread-35] com.netflix.discovery.DiscoveryClient    : DiscoveryClient/192.168.0.106:8888 - deregister  status: 200
    2019-07-10 00:40:43.893  INFO [,,,] 15144 --- [      Thread-35] com.netflix.discovery.DiscoveryClient    : Completed shut down of DiscoveryClient
    Disconnected from the target VM, address: '127.0.0.1:9892', transport: 'socket'
    
    Process finished with exit code 0
    562690440488, current=DOWN, previous=UP]
    2019-07-10 00:40:40.497  INFO [] 15144 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient    : DiscoveryClient/192.168.0.106::8888 - registration status: 204
    2019-07-10 00:40:40.498  INFO [,,,] 15144 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient    : DiscoveryClient/192.168.0.106:8888: registering service...
    2019-07-10 00:40:40.502  INFO [,,,] 15144 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient    : DiscoveryClient/192.168.0.106:8888 - registration status: 204
    2019-07-10 00:40:40.821  WARN [,,,] 15144 --- [ender@10545d02}] s.c.a.AnnotationConfigApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'eurekaRibbonClientConfiguration': Unsatisfied dependency expressed through field 'eurekaConfig'; nested exception is org.springframework.beans.factory.BeanCreationNotAllowedException: Error creating bean with name 'eurekaInstanceConfigBean': Singleton bean creation not allowed while singletons of this factory are in destruction (Do not request a bean from a BeanFactory in a destroy method implementation!)
    2019-07-10 00:40:40.862  INFO [] 15144 --- [      Thread-35] com.alibaba.druid.pool.DruidDataSource   : {dataSource-1} closed
    2019-07-10 00:40:40.863  INFO [] 15144 --- [      Thread-35] com.netflix.discovery.DiscoveryClient    : Shutting down DiscoveryClient ...
    2019-07-10 00:40:43.864  INFO [] 15144 --- [      Thread-35] com.netflix.discovery.DiscoveryClient    : Unregistering ...
    2019-07-10 00:40:43.877  INFO [] 15144 --- [      Thread-35] com.netflix.discovery.DiscoveryClient    : DiscoveryClient_/192.168.0.106:8888 - deregister  status: 200
    2019-07-10 00:40:43.893  INFO [] 15144 --- [      Thread-35] com.netflix.discovery.DiscoveryClient    : Completed shut down of DiscoveryClient
    Disconnected from the target VM, address: '127.0.0.1:9892', transport: 'socket'
    
    Process finished with exit code 0

    网上大部分说是没有添加web依赖,于是在pom.xml中添加了web依赖:

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
  3. 启动,但是仍然是注册到eureka后又关闭,想了下,既然这种情况是由于应用不是web应用引起的,已经添加了web依赖,那么就可能是之前的配置将应用标记为了非web应用,于是删除之前的配置,果然可以启动注册到eureka了

转载于:https://www.cnblogs.com/flyleekungfu/p/11161441.html

  • 5
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值