In one of my projects I let Spring Boot automatically bind domain objects from the database.

This fails in the reduced unit test setup, because DomainClassConverter is not available. But it can be mocked!

I got some hints on Stack Overflow:

These hints did not help me, because mocking the required method call alone caused issues with other method calls failing.

Then I read about reconfiguring @MockBean with Answer.CALL_REAL_METHODS. This did not work either, because the bean was not initialized properly (converterCache was null).

A @SpyBean configuration was the solution: @SpyBean does initialize the bean and it is possible to selected method calls:

@WebMvcTest(controllers = InvoiceItemController.class)
@WithMockUser(roles = {"INVOICE"})
public class InvoiceItemControllerTest extends BaseControllerTest implements CrudControllerTest {

    protected MockMvc mockMvc;

    @SpyBean(name = "mvcConversionService")
    FormattingConversionService webConversionService;

    Invoice invoice;

    public void initMocks() {
        invoice = new Invoice();

    public void createForm() throws Exception {
        // workaround for missing DomainClassConverter in reduced test setup
                                -> argument.getObjectType().equals(String.class)),
                        argThat((ArgumentMatcher<TypeDescriptor>) argument
                                -> argument.getObjectType().equals(Invoice.class)));

                .convert(eq("3"), any(TypeDescriptor.class), any(TypeDescriptor.class));

        getMockMvc().perform(get(getBaseUrl() + "/create").param("invoice", "3"))

Using @SpyBean with WebConversionService did not work because of a missing default constructor. Therefore I switched to FormattingConversionService wich is configured in WebMvcAutoConfiguration as mvcConversionService