Why Spring MVC does not allow to expose Model or BindingResult to an @ExceptionHandler?

后端 未结 6 1105
时光说笑
时光说笑 2021-02-12 18:41

Situation

I\'m trying to group the code that logs the exceptions and render a nice view in a few methods. At the moment the logic is sometime in the @RequestHand

6条回答
  •  故里飘歌
    2021-02-12 18:48

    I had the same problem to "add" FunctinalException to ourthe BindingResult

    To resolve it, we use aop, if the controller method throws a runtime exception (or the one you want), the aop catch it and update the bindingresult or model (if they are args of the method).

    The method has to be annoted with a specific annotation containing the error path (configurable for specific exception if necessary).

    It is not the best way because developer must not forget to add args that he don't use in its method but Spring does not provide a simple system to do this need.

提交回复
热议问题