[英]Exception Handling Spring
We are converting our app from Struts 1.2 to Springs 3.0. 我们正在将我们的应用程序从Struts 1.2转换为Springs 3.0。 So we are making changes in exception handling done in our Struts 2 code.
因此,我们正在更改在Struts 2代码中完成的异常处理。
As per my undestanding this is how we need to do. 按照我的理解,这就是我们需要做的。
Now I have following questions. 现在我有以下问题。
Have a look at Spring's facilities for exception handling: 看一下Spring用于异常处理的工具:
http://static.springsource.org/spring/docs/3.1.x/spring-framework-reference/html/mvc.html#mvc-exceptionhandlers http://static.springsource.org/spring/docs/3.1.x/spring-framework-reference/html/mvc.html#mvc-exceptionhandlers
The idea is similar to your approach for using AOP, but requires a lot less configuration. 这个想法类似于您使用AOP的方法,但是所需的配置要少得多。 Essentially, you register a handler for any kind of unchecked exception your code throws.
本质上,您为代码引发的任何未经检查的异常注册处理程序。 This lets you test your code by asserting whether or not the exception was thrown, and decoupling that logic from handling and recovering from the exception.
这使您可以通过断言是否引发异常来测试代码,并将该逻辑与处理异常以及从异常中恢复脱钩。
The @ExceptionHandler value can be set to an array of Exception types. 可以将@ExceptionHandler值设置为Exception类型的数组。 If an exception is thrown matches one of the types in the list, then the method annotated with the matching @ExceptionHandler will be invoked.
如果抛出的异常与列表中的一种类型匹配,则将调用以匹配的@ExceptionHandler注释的方法。 If the annotation value is not set then the exception types listed as method arguments are used.
如果未设置注释值,则使用列为方法参数的异常类型。
Spring uses AOP internally which you need not work on. Spring内部使用AOP,您无需进行任何操作。 It gives you all the bolt and nuts code.
它为您提供了所有螺栓和螺母代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.