Spring AOP生成的代理类的位置

Spring AOP生成的代理类的位置

问题描述:

仅出于学习和理解代理的目的,我想看看Spring AOP生成的代理类.它在Eclipse生成的classes文件夹中不存在.

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.

有人可以告诉我它的位置吗?

Can somebody tell me its location?

如果您使用的是基于接口的代理(默认),则Spring使用

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.