How to set default value of exported as false in rest resource spring data rest

前端 未结 4 716

I want to use RestResource annotation of spring data rest. As you know it exposes ALL CRUD methods by default. But I only need findAll method. One way is to set exported val

4条回答
  •  醉酒成梦
    2021-01-20 09:07

    There is an easy and standard solution and I tried and found it working in spring boot 2.0.2 Write a configuration class as shown below and setExposeRepositoryMethodsByDefault(false) and it's done :)

    @Component
    public class SpringRestConfiguration extends RepositoryRestConfigurerAdapter {
        @Override
        public void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) {
            config.setRepositoryDetectionStrategy(RepositoryDetectionStrategy.RepositoryDetectionStrategies.ANNOTATED);
            config.setExposeRepositoryMethodsByDefault(false);
        }
    }
    

提交回复
热议问题