Skip to content

Expose handler method when BindException is thrown from HandlerMethodInvoker [SPR-8178] #12829

@spring-projects-issues

Description

@spring-projects-issues

Clark Duplichien opened SPR-8178 and commented

When using RequestMapping annotated controller methods, you can only have have access to the handler method if you have an Errors object as one of the method arguments, and perform error handling within the method.
This is not ideal for use cases where you want to remove boiler plate code and delegate handling of BindExceptions, but need to have access to the method that (would have been) executed. For example, we have an annotation on the controller method indicating what view the bind errors should be displayed on when a BindExcpetion occurs.
Since the annotation is on the controller method, we're currently having to perform some ugly reflection in the HandlerExceptionResolver that handles the BindException in order to extract the controller method for the request from the HandlerAdapter.
It would be preferable if we could have one of:

  1. The handler method that would have been called exposed in the BindException (or even a subclassed "HandlerMethodBindException" or the like for the case when it fails from HandlerMethodInvoker)
  2. Or the handler method exposed to the HandlerExceptionResolver itself (Though admittedly have no idea how this would work).
  3. Or a (thread-bound) accessor method on AnnotationMethodHandlerAdapter that would return the last resolved controller method.
  4. Or a public method in AnnotationMethodHandlerAdapter that accepts Object handler and HttpServletRequest request, and returns the Method object for the request (what we're currently doing, just with reflection).

Affects: 3.0.3

Issue Links:

Referenced from: commits aa7a100, 5309e43, f752b47

1 votes, 3 watchers

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: webIssues in web modules (web, webmvc, webflux, websocket)status: duplicateA duplicate of another issuetype: enhancementA general enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions