How to prevent some HTTP methods from being exported from my MongoRepository?
Thanks to Oliver, here are the methods to override:
@RepositoryRestResource(collectionResourceRel = "people", path = "people")public interface PersonRepository extends MongoRepository<Person, String> { // Prevents GET /people/:id @Override @RestResource(exported = false) public Person findOne(String id); // Prevents GET /people @Override @RestResource(exported = false) public Page<Person> findAll(Pageable pageable); // Prevents POST /people and PATCH /people/:id @Override @RestResource(exported = false) public Person save(Person s); // Prevents DELETE /people/:id @Override @RestResource(exported = false) public void delete(Person t);}
This is late reply, but if you need to prevent the global http method for a entity, try it.
@Configurationpublic class DataRestConfig implements RepositoryRestConfigurer { @Override public void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) { config.getExposureConfiguration() .forDomainType(Person.class) .withItemExposure(((metdata, httpMethods) -> httpMethods.disable(HttpMethod.PUT, HttpMethod.POST, ... ))) .withCollectionExposure((metdata, httpMethods) -> httpMethods.disable(HttpMethod.PUT, HttpMethod.POST, ...)); }}
Why not just use like this?
@Configurationpublic class SpringDataRestConfiguration implements RepositoryRestConfigurer { @Override public void configureRepositoryRestConfiguration(RepositoryRestConfiguration restConfig) { restConfig.disableDefaultExposure(); }}