Spring Security's MockMvc Support does not currently work with WebTestClient. This is a list of issues related to this problem. It includes both adding the feature to support Spring Security MockMvc and WebTestClient and (for the meantime) fixing bugs around users attempting to improperly use these features together.

  • gh-10900
  • gh-10899
  • gh-10841

Comment From: rstoyanchev

After the changes in https://github.com/spring-projects/spring-framework/issues/31298, it should now be possible to sort this out. There is a FrameworkExtensionTests class that provides an example of how it works with MockMvcWebTestClient.