spring-framework icon indicating copy to clipboard operation
spring-framework copied to clipboard

Deprecated MockMvcClientHttpRequestFactory is required to create a test HTTP client proxy

Open forketyfork opened this issue 2 days ago • 0 comments

MockMvcClientHttpRequestFactory was deprecated in Spring 7 with the following deprecation message: Deprecated in favor of RestTestClient.bindTo(MockMvc).

I use this factory in the following test code, to create a test client proxy from an HTTP service interface:

fun myApiTestClient(mockMvc: MockMvc): MyApi {
    val testRestClient = RestClient.builder()
        .requestFactory(MockMvcClientHttpRequestFactory(mockMvc))
        .build()
    val adapter = RestClientAdapter.create(testRestClient)
    val testHttpServiceProxyFactory = HttpServiceProxyFactory.builderFor(adapter).build()
    return testHttpServiceProxyFactory.createClient<MyApi>()
}

// ...

@HttpExchange(accept = [MediaType.APPLICATION_JSON_VALUE])
interface MyApi {
    @GetExchange("/example")
    fun example(): ExampleResponse
}

However, I couldn't find an adapter for HttpServiceProxyFactory that would allow to use it with RestTestClient instead of RestClient.

Is there a proper way to create a test client proxy with mock MVC in Spring 7, or can this be supported?

forketyfork avatar Dec 10 '25 09:12 forketyfork