I know this might feel like a duplicate of this.
When to use @RestController vs @RepositoryRestResource
But I have a few things which were not addressed in that question.
With
@RepositoryRestResource
, every method is by default exposed. Which I feel is a bit annoying. Correct me if I am wrong here. For example in the below case@RepositoryRestResource public interface ProductRepository extends MongoRepository<Product, String> {}
If I want only findAll() and findOne() to be exposed and not any other methods, especially delete. To achieve this I need to do something like this
@RepositoryRestResource
public interface ProductRepository extends MongoRepository<Product, String> {
@RestResource(exported = false)
@Override
default void delete(String s) {
}
@RestResource(exported = false)
@Override
default void delete(Product product) {
}
@RestResource(exported = false)
@Override
default void delete(Iterable<? extends Product> iterable) {
}
@RestResource(exported = false)
@Override
default void deleteAll() {
}
}
Which I feel is really lot of unwanted code. This is much better to do with Rest Controller approach
I believe it is better to return any value from REST endpoints using ResponseEntity. But with spring-data-rest approach, I am not sure how to do it.
I could not find any way to unit test(Not IT) REST endpoints exposed by the RepositoryRestResource. But with REST controller approach, I can test my REST endpoints using
MockServletContext
,MockMvc
,MockMvcBuilders
Given all these, is it still advantageous to use sping-data-rest(except for HATEOS)?
please clarify