[jboss-user] [JBoss AOP] - Dynamic AOP and User-Defined Class Loader

shu_boston do-not-reply at jboss.com
Tue May 6 00:57:14 EDT 2008


Hi,

I want to weave interceptors which loaded by a user-defined class loader (like NetworkClassLoader), but I got a javassist.NotFoundException. My code is as follows


  | ClassLoader loader = new ... // my class loader
  | Thread.currentThread().setContextClassLoader(loader);
  | Class clazz = Class.forName("aspect.GreetingInterceptor", false, loader); 
  | 
  | AdviceBinding binding = new AdviceBinding();
  | binding.setPointcutExpression("execution(* *.Test->*(..))");
  | binding.addInterceptor(clazz);
  | AspectManager.instance().addBinding(binding);
  | 
  | Test t = new Test();
  | t.print();
  | 	

My class loader reads aspect.GreetingInterceptor.class file and calls defineClass() to load it. At the end of the code above, aspect.GreetingInterceptor is supposed to be invoked. When aspect.GreetingInterceptor is in classpath and specified as addInterceptor(aspect.GreetingInterceptor.class), it works fine. However, I got following exception when aspect.GreetingInterceptor is loaded dynamically.


  | Exception generating JoinPoint_print4216308509294254048_1: aspect.GreetingInterceptor
  | java.lang.RuntimeException: Error generating joinpoint class for joinpoint Method[method=public void
  |  Test.print()]
  | 	at org.jboss.aop.instrument.JoinPointGenerator.doGenerateJoinPointClass(JoinPointGenerator.java:321
  | )
  | 	...
  | 
  | Caused by: javassist.NotFoundException: aspect.GreetingInterceptor
  | 	at javassist.ClassPool.get(ClassPool.java:436)
  | 	at org.jboss.aop.util.ReflectToJavassist.classToJavassist(ReflectToJavassist.java:49)
  | 	at org.jboss.aop.instrument.JoinPointGenerator$AdviceSetup.<init>(JoinPointGenerator.java:1390)
  | 	...
  | 

Does anyone know how I can use dynamically loaded class as an interceptor?

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4148725#4148725

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4148725



More information about the jboss-user mailing list