Method and internal spring aop aspectJ

1)spring aop与aspectJ

AspectJ itself does not support run- time weaving, daily use, we often hear back, spring aop achieved using aspectJ, it sounds like the spring aop is entirely dependent on aspectJ

In fact, spring aop to achieve is through dynamic proxy (jdk dynamic proxy or dynamic proxy cglib's), it just uses the Annotation aspectJ and did not use it compile and weaver, for this can be seen in this article , That spring is not used directly aspectJ realization of aop

The difference between spring aop and aspectJ

Read a lot of articles and blog source, my understanding of spring aop and aspectJ of something like this;
1) spring aop use a subset of the AspectJ syntax, some of the method call, class member set / get support for syntax and other aspectJ do not support it
2) spring aop underlying dynamic proxy, so limited by this point, you can not do some enhancements, such as calling their methods can not walk agency

 



Author: Kat end
link: https: //www.jianshu.com/p/958af6a90477
Source: Jane book
Jane book copyright reserved by the authors, are reproduced in any form, please contact the author to obtain authorization and indicate the source.
 
2) spring aop internal function interception

Look at the following example:

@Component
public class A{ public void method1(){ method2(); } public void method2(){ //... } } 

This time method2 is 无法被切到the

When faced with this problem before, and I especially do not understand, and now want the underlying implementation under aop very easy to understand.

Before writing the dynamic proxy and cglib dynamic proxy implementation jdk principle , we know jdk dynamic proxy agent is achieved by way of a dynamically generated class, that is代理是不会修改底层类字节码 ,

Why method2 () not to cut, Author: Kat end link: https: //www.jianshu.com/p/958af6a90477 Source: Jane book Jane book copyright reserved by the authors, are reproduced in any form, please contact the author authorized and to indicate the source. 因为a.method1()执行的方法,最后调用的不是 代理对象.method2(),而是它自己的method2()(this.method2()) 这个方法本身没有任何改动




 
There are two solutions:

1, in order to be cut by wonderful manner:

@Component
public class A{ @Autowired private A a; public void method1(){ a.method2(); } public void method2(){ //... } }


2)

When regain proxy object called internally
public class ServiceAImpl the implements ServiceA {
ServiceAImpl serviceA;
public void function01 (...) {
...
serviceA = SpringContextUtil.getBeanByClass (this.getClass ());
serviceA.function02 (...) ;
}
...
public void function02 (...) {
doSomething;
}
}
---------------------
OF: russ44
source: CSDN
description: https: / /blog.csdn.net/russ44/article/details/78975997
Disclaimer: This article is a blogger original article, reproduced, please attach Bowen link!

Guess you like

Origin www.cnblogs.com/silyvin/p/11260615.html