永发信息网

如何控制spring aop 拦截顺序

答案:1  悬赏:10  手机版
解决时间 2021-01-04 02:14
  • 提问者网友:不爱我么
  • 2021-01-03 15:19
如何控制spring aop 拦截顺序
最佳答案
  • 五星知识达人网友:深街酒徒
  • 2021-01-03 16:18
创建拦截类:
@Aspect
public class MyAspect{


@Before("execution(* t.t..service.*Service.*(..))")
public void before(JoinPoint point) throws Throwable {
System.out.println("执行方法:" + point.getSignature().getDeclaringTypeName() + "." + point.getSignature().getName());
}


@After("execution(* t.t..service.*Service.*(..))")
public void after(JoinPoint point) throws Throwable {
System.out.println("执行完成:" + point.getSignature().getDeclaringTypeName() + "." + point.getSignature().getName());
}


@Around("execution(* cn.cydl.dlj..service.*Service.*(..))")
public Object around(ProceedingJoinPoint point) throws Throwable {
System.out.println("执行前...");
// 这里相当于@Before
Object obj = point.proceed();// 调用方法具体执行过程,如果不调用,这原来的方法就不会执行了
// obj问原来的方法返回值,如果不返回obj,则原来的方法即时有return也不会返回任何值
// 这里相当于@After
System.out.println("执行后...");
return obj;
}
}
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯