Spring-mvc controller and exception handling

后端 未结 5 1079
夕颜
夕颜 2021-02-09 08:33

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:12

    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.

提交回复
热议问题