I'm using Spring Boot, Spring Data REST, Spring HATEOAS, Hibernate, JPA.
I'm using extensively Spring Data REST in my application and I expose all Repositories of my entities. Unfortunately there are some particular cases that are not so easy to manage. One of that is this:
I've a custom controller:
@Api(tags = "CreditTransfer Entity")
@RepositoryRestController
@RequestMapping(path = "/api/v1")
@PreAuthorize("isAuthenticated()")
public class CreditTransferController {
@RequestMapping(method = RequestMethod.GET, path = "/creditTransfers/{id}")
public ResponseEntity<?> findAll(@PathVariable("id") long id, HttpServletRequest request, Locale locale,
PersistentEntityResourceAssembler resourceAssembler) {
//my code
}
@RequestMapping(method = RequestMethod.DELETE, path = "/creditTransfers/{id}")
public ResponseEntity<?> deleteMovement(@PathVariable("id") long id, HttpServletRequest request, Locale locale,
PersistentEntityResourceAssembler resourceAssembler) {
//my code
}
The problem here is that overriding these endpoints, I am hiding the /search endpoint that Spring Data REST create. And that is very important to me.
I did't find any smart way to make this to work without interfer with defaults endpoints provided from Spring Data REST.
Is there a way to solve my problem?
======================================================================
A small enhancement is using a mapping like this:
@RequestMapping(method = RequestMethod.DELETE, path = "/creditTransfers/{id:[0-9]+}")
In this way my controller doesn't catch the url localhost:8080/api/v1/creditTransfers/search
but still, if I override just the DELETE method, when I try to GET localhost:8080/api/v1/creditTransfers
I've the error Request method 'GET' not supported
. Seems my controller override ALL methods for a specific path and not just the one I set.