每次我使用Pageable参数调用rest控制器方法时,我都会收到“ org.springframework.beans.BeanInstantiationException:无法实例化[org.springframework.data.domain.Pageable]:指定的类为接口”。其他控制器方法可以正常工作。
@Configuration
@EnableWebMvc
@EnableSpringDataWebSupport
public class PaginationConfig extends SpringDataWebConfiguration {
@Override
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
PageableHandlerMethodArgumentResolver resolver = new PageableHandlerMethodArgumentResolver(sortResolver());
resolver.setFallbackPageable(new PageRequest(0, 50));
resolver.setSizeParameterName("p");
resolver.setPageParameterName("s");
argumentResolvers.add(resolver);
super.addArgumentResolvers(argumentResolvers);
}
}
@RestController
@RequestMapping("/element")
public class ElementController {
...
@GetMapping("/pageable")
public Page<Element> getAll(Pageable pageable) {
return finder.getAll(pageable);
}
}
当我打电话给这个
http://localhost:8000/element/pageable?p=0&s=20
我想获取具有适当内容的普通Page对象。