If you’ve tried unit testing a Spring controller that accepts a Pageable
parameter using JUnit 5 and Mockito with MockMvc
, you might have encountered this error:
java.lang.IllegalStateException: No primary or single unique constructor found for interface org.springframework.data.domain.Pageable
This happens because, in a standalone MockMvc
test (without loading the full Spring context), Spring doesn’t automatically know how to convert query parameters like page
, size
, and sort
into a Pageable
object. Without the proper resolver, it tries to instantiate Pageable
directly, which fails because it’s an interface.