0

With CGLIB I can do

final var enhancer = new Enhancer();
enhancer.setUseCache(false);
enhancer.setSuperclass(superClazz);
enhancer.setCallback(...);
enhancer.setClassLoader(getClass().getClassLoader());   // This

However with Javassist I can't find a way to set the ClassLoader. Any idea?

EDIT: omg, should I just subclass ProxyFactory? That's weird.

LppEdd
  • 20,274
  • 11
  • 84
  • 139

2 Answers2

1

You can set the classloader by adding ClassPaths to the CtClass. See answer to question: get CtClass using specific ClassLoader

Nicholas
  • 15,916
  • 4
  • 42
  • 66
0
// Kotlin
ProxyFactory.classLoaderProvider = ProxyFactory.ClassLoaderProvider { javaClass.classLoader }

This doesn't seem safe imho. But that's how it's done apparently, per documentation.
Alternatively, just subclass ProxyFactory.

LppEdd
  • 20,274
  • 11
  • 84
  • 139