Custom default headers for REST API only using Spring Data REST

后端 未结 3 2161
我寻月下人不归
我寻月下人不归 2020-12-09 14:16

I have a use case where my application hosts REST API and web application and we need to add custom header to REST APIs only. REST APIs are enabled through Spring Data REST.

3条回答
  •  甜味超标
    2020-12-09 14:40

    As Spring Data REST is built on top of Spring MVC, the easiest way is to configure a custom HandlerInterceptor as described in the reference documentation.

    With Spring Data REST the easiest way is to extend RepositoryRestMvcConfiguration and override repositoryExporterHandlerMapping, call the parent method and then invoke ….setInterceptors(…) on it.

提交回复
热议问题