title: spring interceptor doesn't add header to @RestController services
body: <p>I have following interceptor:</p>
  
  <pre><code>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");
      }
  }
  </code></pre>
  
  <p>I checked - spring invokes its on each http resquest.</p>
  
  <p>I notice strange thing. It works fine for controllers like this:</p>
  
  <pre><code>@Controller
  public class AdminViewController {
      @GetMapping ("data")
      public String dataTemplate() {
          return "data";
      }
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/gFiaR.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gFiaR.jpg" alt="enter image description here"></a></p>
  
  <p>But it doesn't add response header to controller like this:</p>
  
  <pre><code>@RestController
  @RequestMapping(Constants.MY_API_URL)
  public class DataServiceController {
       @PostMapping(value = "/mapping", consumes = "application/json")
       public ResponseEntity&lt;Void&gt; saveMapping(@RequestBody MappingDTO mapping, HttpServletRequest request) {
          ...
          return new ResponseEntity&lt;&gt;(CREATED);
      }
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/l6NQB.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/l6NQB.jpg" alt="enter image description here"></a></p>
  
  <p>But I can't explain it because interceptor is invoking. </p>
  
  <p>How can I add header for all request responses?</p>