I'm having a problem to expose RevisionRepository
(Spring Data Envers) endpoints for my repository which extends RevisionRepository
as below :
@RepositoryRestResource(path = "disciplines", itemResourceRel = "disciplines")
public interface DisciplineRepository extends
RevisionRepository<Discipline, Integer, Integer>,
CrudRepository<Discipline, Integer>{
@RestResource(path = "findByName", rel = "findByName")
List<Discipline> findByName(String name);
}
Only findByName
method is exposed, is there any other way to expose the methods in RevisionRepository
? I've also tried to override those methods in DisciplineRepository
but it doesn't work.
Thank You...
Spring Data REST builds on top of Spring Data repositories, analyzes your application's domain model and exposes hypermedia-driven HTTP resources for aggregates contained in the model.
It is not recommended in real-world applications as you are exposing your database entities directly as REST Services. While designing RESTful services, the two most important things that we consider are the domain model and the consumers. But, while using Spring Data REST, none of these parameters are considered.
REST stands for REpresentational State Transfer. It is developed by Roy Thomas Fielding, who also developed HTTP. The main goal of RESTful web services is to make web services more effective. RESTful web services try to define services using the different concepts that are already present in HTTP.
Advantages of using Spring BootIt allows you to create REST APIs with minimal configurations. A few benefits of using Spring Boot for your REST APIs include: No requirement for complex XML configurations. Embedded Tomcat server to run Spring Boot applications.
You'll have to write a custom controller method to implement this, something like the following:
@Autowired
private DisciplineRepository disciplineRepository;
@RequestMapping(value = "/disciplines/{id}/changes", method = RequestMethod.GET)
public ResponseEntity<Resource<RevisionsObject>> getDisciplineRevisions(@PathVariable(value = "id")Discipline discipline) {
if (discipline != null) {
Revisions<Integer, Discipline> disciplineRevisions = disciplineRepository.findRevisions(discipline.getId());
return new ResponseEntity<>(new Resource<>(disciplineRevisions), HttpStatus.OK);
} else {
throw new ResourceNotFoundException();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With