Search code examples
javaspringaopspring-aopcglib

Spring change cglib


I am use Spring in my app, when we have some class that doesn't implements any interface, Spring will use "cglib" to proxy.

Can I change the cglib to other lib in Spring? If yes, How can I do it?

Thanks!

[EDIT] Hi, I was wanting because I have problems with PermGen when I use CGLIB, the proxys instance are not cleaning when I do hotdeploy. Yes, I can change for other stretegy, Aspect etc...


Solution

  • Spring only supports JDK (interface only) and CGLIB based (for classes) proxying, and while it's not explicitly mentioned, it also uses Objenesis with CGLIB for proxying classes with no default constructor. Also see their issues regarding this at https://jira.spring.io/browse/SPR-8190 and https://jira.spring.io/browse/SPR-5654 for further reference. That means there's no drop-in replacement or configuration options in Spring to switch to some other proxy creation method.

    If you're still willing to explore uncharted territories, the DefaultAopProxyFactory might be a good place to start as it seems it's a central piece of the proxy creation code in Spring, the proxy creator classes use it as a factory through their common superclass ProxyCreatorSupport.