有人可以解释一下吗?目标切入点指示符 [英] Can somebody explain this & target pointcut designators
问题描述
我是 Spring AOP 的新手,正在阅读切入点指示符的文档.这和目标指示符对我来说听起来一样.有人可以用一个更好/更干净的例子来解释吗?谢谢
I am new to Spring AOP and was reading the docs for pointcut designators. Both this and target designators sound same to me. Can someone explain with a better/cleaner example? Thanks
this - 将匹配限制为连接点(使用 Spring AOP 时的方法执行),其中 bean 引用(Spring AOP 代理)是给定类型的实例
eg: this(com.xyz.service.AccountService)
代理实现 AccountService 接口的任何连接点(仅在 Spring AOP 中执行方法):
any join point (method execution only in Spring AOP) where the proxy implements the AccountService interface:
target - 限制匹配连接点(使用 Spring AOP 时的方法执行),其中目标对象(被代理的应用程序对象)是给定类型的实例
eg: target(com.xyz.service.AccountService)
目标对象实现 AccountService 接口的任何连接点(仅在 Spring AOP 中的方法执行)
any join point (method execution only in Spring AOP) where the target object implements the AccountService interface
链接:http://docs.spring.io/spring/docs/3.0.x/spring-framework-reference/html/aop.html
推荐答案
可用的不同代理方法(JDK 和 CGLIB)允许您向对象添加比其继承的类型更多的类型.例如,您可以声明一个 Foo
bean,它不扩展任何类(Object
除外)并且不实现任何接口.无论出于何种原因,您都可以决定要代理此 bean 并使其实现 Bar
接口并扩展 SomeRandomType
类.这里的目标对象是 Foo
类型的 bean.Spring 代理是一个对象,它委托给目标 bean,共享其类型,此外还可以有更多类型,如上例所示.
The different proxying methods available, JDK and CGLIB, allow you to add more types to your object than those that it inherits. For example, you can declare a Foo
bean that extends no classes (except Object
) and implements no interfaces. For whatever reason, you can decide that you want to proxy this bean and make it implement the Bar
interface and extend the SomeRandomType
class. The target object here would be the bean of type Foo
. The Spring proxy is an object that delegates to the target bean, shares its type, and additionally can have more types, as in the example above.
因此,target
指代被代理的 bean,this
指代代理.
Therefore target
refers to the proxied bean and this
refers to the proxy.
这篇关于有人可以解释一下吗?目标切入点指示符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!