Spring AOP pointcut的 this target within的区别
本文内容纲要:Spring AOP pointcut的 this target within的区别
Vehicle 接口
VehicleImp 实现类
Main函数调用.
Vehicle v1 = (Vehicle)context.getBean("vehicleimp");
v1.drive();
<aop:pointcut id="pointcut-pose" expression="execution(* *..drive()) and this(VehicleImp) "/> 匹配不到
<aop:pointcut id="pointcut-pose" expression="execution(* *..drive()) and this(Vehicle) "/> 匹配到
<aop:pointcut id="pointcut-pose" expression="execution(* *..drive()) and target(VehicleImp) "/> 匹配到
<aop:pointcut id="pointcut-pose" expression="execution(* *..drive()) and target(Vehicle) "/> 匹配到
<aop:pointcut id="pointcut-pose" expression="execution(* *..drive()) and within(VehicleImp) "/> 匹配到
<aop:pointcut id="pointcut-pose" expression="execution(* *..drive()) and within(Vehicle) "/> 匹配不到
<aop:pointcut id="pointcut-pose" expression="execution(* *..drive()) and within(Vehicle+) "/> 匹配到
说明:
1.this(VehicleImp)匹配不到,因为context.getBean()获得的对象v1是个被包装过的代理对象.不是VehicleImp类型. target(VehicleImp)能匹配到,匹配的是被代理的实际(VehicleImp)对象.
2.代理类型和被代理类型都符合接口Vehicle,this(Vehicle)和target(Vehicle)都能匹配到.
3.with和target的目标对象一样是实际被代理的对象(本文中VehicleImp).within不支持继承关系.所以within(Vehicle)没匹配到.可以使用+,within(Vehicle+)匹配.
总结:this是匹配代理后的包装过的对象, target和within匹配被代理原本的对象(vehicleimp).within不匹配继承关系.
本文内容总结:Spring AOP pointcut的 this target within的区别
原文链接:https://www.cnblogs.com/spelunky/p/spring-aop-this-target-within.html
以上是 Spring AOP pointcut的 this target within的区别 的全部内容, 来源链接: utcz.com/z/362882.html