-
Notifications
You must be signed in to change notification settings - Fork 38.8k
Closed
Labels
in: webIssues in web modules (web, webmvc, webflux, websocket)Issues in web modules (web, webmvc, webflux, websocket)type: bugA general bugA general bug
Milestone
Description
William Ashley opened SPR-6008 and commented
@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
Affects: 3.0 M3
Issue Links:
- @ResponseStatus does not work with @ExceptionHandler [SPR-6961] #11626
@ResponseStatusdoes not work with@ExceptionHandler("is duplicated by")
Referenced from: commits 3b7691d
Metadata
Metadata
Assignees
Labels
in: webIssues in web modules (web, webmvc, webflux, websocket)Issues in web modules (web, webmvc, webflux, websocket)type: bugA general bugA general bug