SpringBoot的测试需注意是否排除了Tomcat导致“Unable to start ServletWebServerApplicationContext“

最近在项目里,在进行测试的时候报了个:

java.lang.IllegalStateException: Failed to load ApplicationContext
Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean

不是技术论坛中大家常说的应用入口类缺少@SpringBootApplication标注,或者是Spring bean缺少@EnableAutoConfiguration标注等问题。

还可能是在你的项目里,你的项目是排除了Springboot的tomcat(想用自己的嘛)

但是在test方式启动时就会报以上错误,所以需要将排除注释掉,其余的方案我还没找到

<!--SpringBoot 要集成 SpringMVC 进行 Controller 的开发,所以项目要导入 web 的启动依赖。-->
    <!-- 继承父工程 spring-boot-starter-parent 启动器后,子工程的启动器版本无需再指定 -->
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>

      <!--<exclusions>-->
      <!--  <exclusion>-->
      <!--    <groupId>org.springframework.boot</groupId>-->
      <!--    <artifactId>spring-boot-starter-tomcat</artifactId>-->
      <!--  </exclusion>-->
      <!--</exclusions>-->
    </dependency>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值