Spring-mvc controller and exception handling

后端 未结 5 1544
星月不相逢
星月不相逢 2021-02-09 08:35

Would like to ask you a best practice question where a spring-mvc controller is concerned. Please review the code below:

    @Autowired
    SomeService service;
         


        
5条回答
  •  轮回少年
    2021-02-09 09:06

    I would say you have three strategies depending on your use case.

    There are roughly three strategies: HandlerExceptionResolver, @ExceptionHandler and handling exceptions internally within action.

    The use cases for these are: common exception handler for whole application, whole controller, specific action accordingly.

提交回复
热议问题