linda1048195
2015-04-25 22:05
aop after-returning 和after的区别? 难道只是执行顺序的先后问题呢?大家都是在方法执行后返回,区别在哪里呢
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
Object result;
try {
//@Before
result = method.invoke(target, args);
//@AfterReturning
return result;
} catch (InvocationTargetException e) {
Throwable targetException = e.getTargetException();
//@AfterThrowing
throw targetException;
} finally {
//@After
}
}
兄弟,到底哪个版本是对的???????
阿萨德
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
Object result;
try {
//@Before
result = method.invoke(target, args);
//@After
return result;
} catch (InvocationTargetException e) {
Throwable targetException = e.getTargetException();
//@AfterThrowing
throw targetException;
} finally {
//@AfterReturning
}
}
try{ try{ //@Before method.invoke(..); }finally{ //@After } //@AfterReturning }catch(){ //@AfterThrowing }
try { // 执行前置通知; // 执行目标方法; // 执行返回通知; } catche(Exception e) { // 执行异常通知; } finally { // 执行后置通知; }
应该是这样的...
//限定了返回值,可不写,注意如果出现异常,则该设定不起作用,after returing对应的方法不被执行
<aop : after-returning returning = "retVar" method = "" pointcut-ref = "" />
//after的执行是在after returning之后,但无论方法是否正常结束, after通知都会被执行
<aop : after method = "" pointcut = " " />
after 对应 target 执行之后, afterReturning 对应在 target 处理后结果返回增强处理
可以看老师例子中after-returning和after对应的输出内容进行对比
Spring入门篇
268785 学习 · 963 问题
相似问题