You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

添加Spring Cloud Contract Stubrunner依赖致JUnit5测试中ServerHttpSecurity无法自动装配

Spring Cloud Contract Stub Runner 4.0.3 引发Spring Security WebFlux Bean创建失败

正在将微服务从Java 11升级至Java 17,同步完成Spring 2到Spring 3、Spring Cloud Contract 2到4的版本升级。添加org.springframework.cloud:spring-cloud-starter-contract-stub-runner:4.0.3依赖后,即使是最基础的标注@SpringBootTest的JUnit 5测试也会报错,提示无法找到org.springframework.security.config.web.server.ServerHttpSecurity类型的合格Bean,导致springSecurityWebFilterChain Bean创建失败。

触发问题的条件

  • 引入org.springframework.cloud:spring-cloud-starter-contract-stub-runner:4.0.3依赖
  • 测试类使用@SpringBootTest注解
  • 项目采用Spring Security的WebFlux配置

已尝试的解决方法

  • 为SecurityConfig类添加@EnableWebFluxSecurity注解
  • 将springSecurityWebFilterChain Bean方法设为public
  • 确保所有依赖均为Maven Central最新版本

内容的提问来源于stack exchange,提问作者Favna

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.15 16:42:11