spring的aop怎么获取切点参数
展开全部
比较简单的方式可以用JoinPoint举个列子。
package com.jf.my.Demo.AOP;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
@Component
@Aspect
public class TestAOPDemoTwo {
@Pointcut("execution(* *.run*(..)) ")
public void any() {
}
@Before(value = "any()")
public void before(JoinPoint join) {
System.out.println("Method 2 before===========");
}
@After(value = "any()")
public void after(JoinPoint join) {
System.out.println("Method 2 after============");
}
@AfterReturning(value = "any()",returning="ji")
public void around(String ji) {// ProceedingJoinPoint pjp
System.out.println("ji");
System.out.println("retrun"+ji);
}
}
直接在方法里写joinpoint,spring会自己注入的,你可以去查查joinpoint的用法之类的东西,然后用下就好了。https://my.oschina.net/itblog/blog/211693这里面介绍的挺不错的
package com.jf.my.Demo.AOP;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
@Component
@Aspect
public class TestAOPDemoTwo {
@Pointcut("execution(* *.run*(..)) ")
public void any() {
}
@Before(value = "any()")
public void before(JoinPoint join) {
System.out.println("Method 2 before===========");
}
@After(value = "any()")
public void after(JoinPoint join) {
System.out.println("Method 2 after============");
}
@AfterReturning(value = "any()",returning="ji")
public void around(String ji) {// ProceedingJoinPoint pjp
System.out.println("ji");
System.out.println("retrun"+ji);
}
}
直接在方法里写joinpoint,spring会自己注入的,你可以去查查joinpoint的用法之类的东西,然后用下就好了。https://my.oschina.net/itblog/blog/211693这里面介绍的挺不错的
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询