How to add Custom Interceptor in Spring data rest (spring-data-rest-webmvc 2.3.0)

扶醉桌前 提交于 2019-11-29 10:48:05

You should not use repositoryMapping.setInterceptors() - it destoys the internal interceptors Spring placed there, and that's probably the reason some methods stopped working.

I suggest you override jpaHelper() method and put your interceptors into the JpaHelper object in RepositoryRestMvcConfiguration. Spring will should them to the global interceptor list.

But, again, if all you need is authentication, why not use a Spring Security filter?

EDIT: the solution above works only for RepositoryRestHandlerMapping, not for BasePathAwareHandlerMapping.

I suggest you declare a custom MappedInterceptor bean somewhere:

@Bean
public MappedInterceptor myMappedInterceptor() {
    return new MappedInterceptor(new String[]{"/**"}, new MyInterceptor());
}

From my understanding of the source code Spring should automatically add this interceptor to all request handlers.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!