Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean

时间:2021-06-04 14:21:06   收藏:0   阅读:13

在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();
}

 

原文:https://www.cnblogs.com/javahepeng/p/14849034.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!