Isolated Controller Test can’t instantiate Pageable

Original answer:

The problem with pageable can be solved by providing a custom argument handler. If this is set you will run in a ViewResolver Exception (loop). To avoid this you have to set a ViewResolver (an anonymous JSON ViewResolver class for example).

mockMvc = MockMvcBuilders.standaloneSetup(controller)
            .setCustomArgumentResolvers(new PageableHandlerMethodArgumentResolver())
            .setViewResolvers(new ViewResolver() {
                public View resolveViewName(String viewName, Locale locale) throws Exception {
                    return new MappingJackson2JsonView();

Updated (2020):
It is not necessary to add the ViewResolver anymore.

Regarding the parallel answer:
It does not solve the problem for the original question to have this test running without ApplicationContext and/or friends.

Leave a Comment