Can somebody explain this & target pointcut designators

守給你的承諾、 提交于 2019-12-22 06:53:18

问题


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 - limits matching to join points (the execution of methods when using Spring AOP) where the bean reference (Spring AOP proxy) is an instance of the given type

eg: this(com.xyz.service.AccountService)

any join point (method execution only in Spring AOP) where the proxy implements the AccountService interface:

target - limits matching to join points (the execution of methods when using Spring AOP) where the target object (application object being proxied) is an instance of the given type

eg: target(com.xyz.service.AccountService)

any join point (method execution only in Spring AOP) where the target object implements the AccountService interface

Link : http://docs.spring.io/spring/docs/3.0.x/spring-framework-reference/html/aop.html


回答1:


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.

Therefore target refers to the proxied bean and this refers to the proxy.



来源:https://stackoverflow.com/questions/22848738/can-somebody-explain-this-target-pointcut-designators

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!