Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我在 Spring 中有任何预定义的方式来捕获或处理ServletException吗?我的意思是任何可以捕获它们并为它们提供实用方法的注释或类?
ServletException
有几种技术和方法可以使用 Spring 处理 Servlet 异常。我可以将您重定向到这个有趣的链接:
使用 Spring 进行 REST 的异常处理
异常可以在 DispatchServlet 级别、控制器级别或应用程序级别进行管理。您可以选择更适合您需求的方法。
异常处理可以在每个控制器中实现(使用旧的 @ExceptionHandler 或更近且易于使用的 ResponseStatusException),或者在集中所有异常管理的全局异常处理程序中(使用 @ControllerAdvice)