Caught exception while allowing TestExecutionListener [org.xx.ServletTestExecutionListener@xx]

springboot测试类启动报错

ERROR org.springframework.test.context.TestContextManager  : Caught exception while allowing TestExecutionListener [org.springframework.test.context.web.ServletTestExecutionListener@2f112965] to prepare test instance [com.greenzone2.GreenZoneIIApplicationTests@6259f18e]

解决方法,添加webEnvironment配置

@RunWith(SpringRunner.class)
@SpringBootTest(classes = GreenZoneIIApplication.class,webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class GreenZoneIIApplicationTests {
  • DEFINED_PORT:创建一个(reactive) web 应用程序上下文,使用默认端口。
  • MOCK:MOCK 是用的比较多的一个属性。它会判断,当你使用 servlet API 时,则使用模拟 servlet 环境创建 WebApplicationContext;如果是使用 WebFlux,则使用 ReactiveWebApplicationContext;否则,使用常规的 ApplicationContext。
  • NONE:不会指定 SpringApplication.setWebApplicationType。以非 Web 环境来运行。也就是非 Servlet 和 Reactive 环境。
  • RANDOM_PORT:创建一个 web 应用程序上下文,可以是 reactive,也可以是 servlet。它将随机起一个端口并监听。到底是 reactive 还是 Servlet,它会自己根据上下文来判断。
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值