- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个带有以下签名的方法
我想在捕获切点后记录异常,现在当我执行代码时,它会在控制台上抛出异常打印,然后到达我的切点定义的方法,可能是因为它是 @AfterThoring 注释,但有没有可用的 @BeforeThrowing 注释?请建议我能做什么
public void jingleBell(){
System.out.println("Jingle Bell Job...");
throw new RuntimeException("test error");
}
并遵循切入点的建议
@AfterThrowing(pointcut = "execution(* com.dc.lnwsk.adapter.Search.jingleBell())", throwing = "ex")
public void handleException(Throwable ex){
//Log exception
}
最佳答案
异常与方法
不同,在方法
中,可以在调用切入点方法之前更改(编织)代码以调用新方法。
异常是运行时现象,JVM 事先并不知道会抛出某些异常,因此没有@BeforeThrowing。
如果您预先知道异常情况,那么最好在切入点方法上使用@Before
并处理异常情况。
关于Java - Spring AspectJ AfterThrowing,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13753082/
我想使用AOP来拦截所有在服务层抛出的运行时异常,并作为领域异常重新抛出。 @Aspect @Component public class ExceptionWrapperInterceptor {
我有一个带有以下签名的方法 我想在捕获切点后记录异常,现在当我执行代码时,它会在控制台上抛出异常打印,然后到达我的切点定义的方法,可能是因为它是 @AfterThoring 注释,但有没有可用的 @B
当我的系统抛出异常时,应该调用下面的方法,但事实并非如此。它仅在我从注释中删除“throwing”并将“Exception”作为参数时才有效: 不起作用: @AfterThrowing(pointcu
我的应用程序类路径中有aspectjrt-1.5.4.jar、aspectjweaver-1.6.1.jar、org.springframework.aop-3.0.5.RELEASE.jar。 我的
我有以下奇怪的行为。 当我使用命名切入点时,建议的方法在 @AfterThrowing 的主体之前运行带注释的方法。但是如果我使用内联切入点 @AfterThrowing带注释的首先运行。 为什么会这
我遇到了一种情况,我想模拟 Web 服务调用。我使用的方法是,如果服务关闭,它会抛出异常。我打算在 spring 中使用 ThrowAdvice AOP 来使用该异常,并希望抑制该异常并用我的虚拟对象
package test.aop; import org.aspectj.lang.JoinPoint; import org.aspectj.lang.annotation.AfterThrowin
在 AspectJ 中,我想吞下一个异常。 @Aspect public class TestAspect { @Pointcut("execution(public * *Throwable(..
我有以下内容: @AfterReturning("executionOfTrustedAnnotatedMethod()") public void afterReturningFromTrusted
我在使用 AspectJ 使用自定义注释进行切入点时遇到了奇怪的行为。 我使用的切入点是: @AfterThrowing(pointcut="@annotation(com.core.meta.Not
我们使用 Spring AOP 和 Log4j 来登录我们的应用程序。我在应用程序中实现了@Before、@After、@AfterThrowing 建议。但我面临以下问题: 当 catch bloc
当尝试实现一个负责捕获和记录某种类型错误的 Aspect 时,我最初认为使用 AfterThrowing 建议可以实现这一点。然而,他的建议似乎没有捕捉到异常,而只是提供了一个额外的入口点来处理异常。
我对 AOP 完全陌生。我需要建议来编写正确的切入点。我有一个包含所有服务类的服务包。所有类都实现了 Service界面。这个接口(interface)有一个方法 save(entity) .我的建议
我对 AOP 完全陌生。我需要建议来编写正确的切入点。我有一个包含所有服务类的服务包。所有类都实现了 Service界面。这个接口(interface)有一个方法 save(entity) .我的建议
我正在定义 @pointcut 表达式,如下所示。 @Pointcut( "execution(* com.xyz..*(..)) && " + "!within(is
我是一名优秀的程序员,十分优秀!