在春季提出建议

| 如果业务方法正在捕获未重新引发的异常,是否将调用引发建议?     
已邀请:
如果该建议适用于业务方法,则不会调用throw通知,因为它不会看到异常。 如果您想“吃蛋糕(或例外)然后吃”,请将业务逻辑分为另一种方法。例如
public void myBusinessLogic()
{
  try
  {
     myBusinessLogicImpl();  
  }
  catch (BusinessLogicException ex)
  {
  }
}
然后,您可以向
myBusinessLogicImpl()
方法添加throws建议,并吞下异常。     
如果您使用Spring AOP(大多数情况),则不会调用方面。本质上,代码如下所示: 经营方式:
public void businessMethod() {
  try {
    doSomething();
  } catch(BusinessException e) {
    //handle and not rethrow
  }
方面:
try {
  businessMethod();
} catch(BusinessException e) {
  //Aspect advice
}
如您所见,方面不可能“看到”异常。如果您确实希望
BusinessException
能够从
businessMethod()
中逃脱,即使它没有逃脱,也可以使用纯AspectJ代替Spring AOP。它与Spring很好地集成在一起,但是首先需要执行一些核心步骤(编译或加载时编织)。     

要回复问题请先登录注册