Seguindo o exemplo, passo à passo, cheguei a esse erro:
No primary or single unique constructor found for interface org.springframework.data.domain.Pageable
Revisei a aula, e estava fiel ao conteúdo. Pesquisando sobre o erro cheguei nesse link No primary or default constructor found for interface org.springframework.data.domain.Pageable.
Provavelmente algo com a versão 2.6.2 do Spring Boot que estou utilizando. Então seguindo o link acima:
1 - Mudei a notação @EnableSpringDataWebSupport do Main para a classe que estende a org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport.
2 - Além disso, adicionei o PageableHandlerMethodArgumentResolver na lista de resolver pela classe anterior.
3 - Ficou assim:
package xyz.configs;
import java.util.List;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.web.PageableHandlerMethodArgumentResolver;
import org.springframework.data.web.config.EnableSpringDataWebSupport;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
import xyz.interceptors.RequestInterceptor
@Configuration
@EnableSpringDataWebSupport
public class WebMvcConfig extends WebMvcConfigurationSupport {
@Override
protected void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new RequestInterceptor());
super.addInterceptors(registry);
}
@Override
protected void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
argumentResolvers.add( new PageableHandlerMethodArgumentResolver());
super.addArgumentResolvers(argumentResolvers);
}
}
Controller
@RestController
@RequestMapping("/api/topics")
public class TopicsController {
@Autowired
private TopicoRepository repo;
@GetMapping("/with-pageable")
public Page<Topico> fetch(@PageableDefault(size=10) Pageable pageable){
return this.repo.findAll(pageable);
}
}