Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean

在Spring Boot项目中,出现这个错误有两种情况:

一,在main方法所在的类忘记添加@SpringBootApplication

二,缺少依赖,添加即可

1
2
3
4
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>
 如果以上两种都检查没问题,那么就手动配置该bean
 
在配置 @Configuration注解的类中  增加以下代码
 
 

@Bean
public ServletWebServerFactory servletWebServerFactory(){
return new TomcatServletWebServerFactory();
}

  • 相关阅读:
    Product of Array Except Self
    如果裸写一个goroutine pool
    fasthttp 的 goroutine pool 实现探究
    golang实现权重轮询调度算法
    golang学习资料
    获取本机ip
    dnscache --源码笔记
    xsrftoken--源码笔记
    forwardport--源码笔记--注释
    golang 通过exec Command启动的进程如何关闭的解决办法 以及隐藏黑色窗口
  • 原文地址:https://www.cnblogs.com/javahepeng/p/14849034.html