org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean


先說結論,啟動項目時遇到以下報錯: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里添加一段配置(原文鏈接:

    []: https://stackoverflow.com/questions/50231736/applicationcontextexception-unable-to-start-servletwebserverapplicationcontext/50232382

    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了


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



猜您在找 Springboot啟動報錯:Caused by: org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean. spring Boot 出現:org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean. Unable to start web server; nested exception is org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean. Unable to start web server; nested exception is org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean. nested exception is org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.報錯解決 SpringCloud報錯:Caused by: org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean. Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean
 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM