Spring AOP生成的代理类的位置 [英] Location of the proxy class generated by Spring AOP

查看:46
本文介绍了Spring AOP生成的代理类的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只是为了学习理解代理,想看看Spring AOP生成的代理类.它不存在于 Eclipse 生成的类文件夹中.

Just for the sake of learning and understanding proxies, I wanted to see the proxy class generated by Spring AOP. It was not present in the classes folder generated by Eclipse.

谁能告诉我它的位置?

推荐答案

如果您使用基于接口的代理(默认),Spring 使用 Proxy 类来动态地在内存中创建代理.没有与该类关联的 .class 文件.

If you are using interface-based proxies (default), Spring uses Proxy class to create proxy dynamically and in-memory. There is no .class file associated with that class.

使用基于类的代理时(通过 ) Spring 创建您的类的具体子类.在调试器中,您会注意到它们的名称类似于 YourRealService$$EnhancerByCGLIB$$... 但同样,这些类仅在内存中生成,而不存储在磁盘上.

When using class-based proxies (via cglib) Spring creates concrete subclasses of your classes. In the debugger you'll notice they are named something like YourRealService$$EnhancerByCGLIB$$... But again, these classes are only generated in-memory and not stored on disk.

如果你真的想在幕后看到 AOP,你将不得不使用 和编译时编织.工作太多了.所以底线是:只要相信他们的工作.如果他们不这样做:检查堆栈跟踪.

If you really want to see AOP under the hood, you will have to use aspectj and compile-time weaving. Way too much work. So the bottom line is: just trust they work. And if they don't: examine stack traces.

这篇关于Spring AOP生成的代理类的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆