I have following interceptor:
public class SecurityInterceptor extends HandlerInterceptorAdapter {
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
response.addHeader("X-Frame-Options", "DENY");
}
}
I checked - spring invokes its on each http resquest.
I notice strange thing. It works fine for controllers like this:
@Controller
public class AdminViewController {
@GetMapping ("data")
public String dataTemplate() {
return "data";
}
}
But it doesn't add response header to controller like this:
@RestController
@RequestMapping(Constants.MY_API_URL)
public class DataServiceController {
@PostMapping(value = "/mapping", consumes = "application/json")
public ResponseEntity<Void> saveMapping(@RequestBody MappingDTO mapping, HttpServletRequest request) {
...
return new ResponseEntity<>(CREATED);
}
}
But I can't explain it because interceptor is invoking.
How can I add header for all request responses?