3

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?

Tomasz Nurkiewicz
  • 334,321
  • 69
  • 703
  • 674

1 Answers1

8

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.

When using class-based proxies (via ) 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.

If you really want to see AOP under the hood, you will have to use 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.

Tomasz Nurkiewicz
  • 334,321
  • 69
  • 703
  • 674
  • Thanks a lot Tomasz for the wonderful explanation. I will trust they work :) There is one question still in my mind. Why do a lot of people say that while using AOP we should consider memory constraints because AOP creates subclasses. Is this correct? Even if AOP creates classes it uses just the proxied one and not the one created by us. – Khalid Ansari Jul 17 '12 at 10:27
  • @KhalidAnsari: a lot of dynamically generated classes (I don't think this applies to dynamic proxies created via `Proxy`) will occupy PermGen space (not heap). I have never came across any issue with that, but keep that in mind. – Tomasz Nurkiewicz Jul 17 '12 at 11:03
  • How is possible to see them though? Im working on a library that needs to extend the YourRealService$$EnhancerByCGLIB$$ classes but i can't seem to find them – Goncalo Condeco Oct 08 '21 at 20:33