首页 > 解决方案 > spring aop代理对象如何知道调用哪个advice

问题描述

我 kbow 代理对象扩展了目标类并覆盖了非最终方法。我的问题是,当代理对象覆盖目标方法时,它向目标方法添加了哪些额外的代码来调用建议?以及代理如何知道何时调用建议,之前,之后等?

标签: springproxyspring-aop

解决方案


What you are asking is a bit too broad since the code used is quite complex.

I'm not sure why do you want to know the exact implementation details but as starting point you should check how Spring AOP works: https://docs.spring.io/spring/docs/5.1.x/spring-framework-reference/core.html#aop

Spring implements proxying by using CGLIB or the JDK depending the situation (i.e.: if you implement your beans using interfaces, Spring will try to use the JDK). You can check the Proxying mechanisms here: https://docs.spring.io/spring/docs/5.1.x/spring-framework-reference/core.html#aop-proxying

From there you can search for the libraries and check the code used for proxying.

I hope this serves you as a starting point for your reasearch.


推荐阅读