You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
@ResponseStatus on @ExceptionHandler method is ignored [SPR-6008] #10676
@ResponseStatus annotations have no effect when used on @ExceptionHandler methods
Controller:
package com.test;
import java.io.PrintWriter;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.servlet.ModelAndView;
@Controller
public class Test
{
@ExceptionHandler
@ResponseStatus( value=HttpStatus.NOT_ACCEPTABLE )
public ModelAndView exception( Throwable t, PrintWriter out )
{
out.println( "Should be a 406" );
return new ModelAndView();
}
@RequestMapping( "/busted" )
public void get( PrintWriter out )
{
throw new RuntimeException( "foo" );
}
@RequestMapping( "/works" )
@ResponseStatus( value=HttpStatus.ACCEPTED )
public void works( PrintWriter out )
{
out.println( "Should be a 202" );
}
}
Note: I am returning an empty ModelAndView to work around another issue that I will open next.
Everything is fine on the @RequestMapping
$ curl -i "http://localhost/test/works"
HTTP/1.1 202 Accepted
Server: Apache-Coyote/1.1
Content-Length: 17
Date: Fri, 14 Aug 2009 19:27:11 GMT
Should be a 202
But not so on the @ExceptionHandler
$ curl -i "http://localhost/test/busted"
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Content-Length: 17
Date: Fri, 14 Aug 2009 19:27:16 GMT
Should be a 406
Activity
spring-projects-issues commentedon Aug 14, 2009
William Ashley commented
Sorry, should have used the noformat macro
spring-projects-issues commentedon Aug 18, 2009
Arjen Poutsma commented
Edited to add code tags.