I want to use RestResource annotation of spring data rest. As you know it exposes ALL CRUD methods by default. But I only need findAll method. One way is to set exported val
You should implement a custom controller for GET /questions request that will return only the result of findAll method, for example:
@RequiredArgsConstructor
@BasePathAwareController
@RequestMapping("/questions")
public class QuestionController {
private final @NonNull QuestionRepository repository;
private final @NonNull PagedResourcesAssembler assembler;
private final @NonNull EntityLinks links;
@GetMapping
ResponseEntity> get(Pageable pageable) {
return ResponseEntity.ok(assembler.toResource(repository.findAll(pageable),
(ResourceAssembler) question ->
new Resource<>(question,
links.linkToSingleResource(question).withSelfRel())));
}
}
and disable your QuestionRepository to be exported:
@RepositoryRestResource(exported = false)
public interface QuestionRepository extends JpaRepository {
}
Working example.