I am working with Spring Framework 4.3.3
About Spring MVC about handle exceptions I have the following about a @ControllerAdvice (note: not totally valid about logic):
I did realize that mav.setStatus(httpStatus) is executed but finally is ignored.
- If I use mav.setViewName("redirect:/error"); the status 302 is applied
- If I use mav.setViewName("/error"); the status 200 is applied
- If I don't use or not declare mav.setViewName the status 200 is applied
Even when has more sense the 302 status, it to show an error page with some message.
I have two questions from here:
(1) Why the setViewName overrides the HttpStatus value?
(2) In what valid scenario the setStatus is mandatory to be used? I did a research on Google about to get some examples seeing in action the setStatus method and nothing. Of course the better approach is use a @RequestMapping or @GetMapping method that returns a String object (view name) and use Model object.
I know it is trivial, but I am with this doubt.
Note: If I put in the current Spring Reference Documentation (htmlsingle mode) the setStatus term, there are no results.
Thanks by your understanding.