How to prevent some HTTP methods from being exported from my MongoRepository?

后端 未结 3 2093
孤街浪徒
孤街浪徒 2020-12-08 01:07

I\'m using spring-data-rest and I have a MongoRepository like this:

@RepositoryRestResource
interface MyEntityRepository extends MongoRepository

        
3条回答
  •  萌比男神i
    2020-12-08 01:26

    This is late reply, but if you need to prevent the global http method for a entity, try it.

    @Configuration
    public 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, ...));
        }
    }
    

提交回复
热议问题