5 Replies Latest reply on Oct 29, 2008 5:49 AM by alesj

    MC AOP CL issue

    alesj

      As part of my IoC demos
      - http://anonsvn.jboss.org/repos/jbossas/projects/demos/microcontainer/trunk/ioc
      I'm deploying a jar that includes -beans.xml with some aop xml code:

       <interceptor xmlns="urn:jboss:aop-beans:1.0" name="StopWatchInterceptor" class="org.jboss.demos.ioc.annotations.StopWatchInterceptor"/>
      
       <bind xmlns="urn:jboss:aop-beans:1.0" pointcut="execution(* @org.jboss.demos.ioc.annotations.StopWatchLog->*(..)) OR execution(* *->@org.jboss.demos.ioc.annotations.StopWatchLog(..))">
       <interceptor-ref name="StopWatchInterceptor"/>
       </bind>
      
       <bean name="AnnotatedExecutor" class="org.jboss.demos.ioc.annotations.AnnotatedExecutor">
       <constructor>
       <parameter><bean class="org.jboss.demos.ioc.annotations.SimpleExecutor"/></parameter>
       </constructor>
       </bean>
      
       <bean name="SimpleExecutorOnType" class="org.jboss.demos.ioc.annotations.SimpleExecutor">
       <annotation>@org.jboss.demos.ioc.annotations.StopWatchLog</annotation>
       </bean>
      
       <bean name="SimpleExecutorOnMethod" class="org.jboss.demos.ioc.annotations.SimpleExecutor">
       <install method="execute">
       <annotation>@org.jboss.demos.ioc.annotations.StopWatchLog</annotation>
       </install>
       </bean>
      


      This jar includes this StopWatchInterceptor class,
      but I get the following exception:
      JBoss-MC-Demo ERROR [27-10-2008 15:45:03] AbstractKernelController - Error installing to Described: name=AnnotatedExecutor state=PreInstall
      java.lang.RuntimeException: java.lang.ClassNotFoundException: org.jboss.demos.ioc.annotations.StopWatchInterceptor
       at org.jboss.aop.microcontainer.beans.GenericBeanAspectFactory.doCreate(GenericBeanAspectFactory.java:135)
       at org.jboss.aop.microcontainer.beans.GenericBeanAspectFactory.createPerVM(GenericBeanAspectFactory.java:90)
       at org.jboss.aop.AspectManager.createPerVmAspect(AspectManager.java:1942)
       at org.jboss.aop.AspectManager.getPerVMAspect(AspectManager.java:1918)
       at org.jboss.aop.Domain.getPerVMAspect(Domain.java:788)
       at org.jboss.aop.Domain.getPerVMAspect(Domain.java:773)
       at org.jboss.aop.advice.ScopedInterceptorFactory.create(ScopedInterceptorFactory.java:69)
       at org.jboss.aop.Advisor.createInterceptorChain(Advisor.java:1318)
       at org.jboss.aop.Advisor.pointcutResolved(Advisor.java:1929)
       at org.jboss.aop.MethodMatchInfo.applyBinding(MethodMatchInfo.java:152)
       at org.jboss.aop.MethodMatchInfo.overridePopulateBindings(MethodMatchInfo.java:143)
       at org.jboss.aop.MethodMatchInfo.populateBindings(MethodMatchInfo.java:92)
       at org.jboss.aop.Advisor.finalizeMethodChain(Advisor.java:1540)
       at org.jboss.aop.ClassContainer.makeInterceptorChains(ClassContainer.java:347)
       at org.jboss.aop.ClassContainer.createInterceptorChains(ClassContainer.java:313)
       at org.jboss.aop.ClassContainer.rebuildInterceptors(ClassContainer.java:138)
       at org.jboss.aop.ClassContainer.initializeClassContainer(ClassContainer.java:72)
       at org.jboss.aop.proxy.container.ClassProxyContainer.initialise(ClassProxyContainer.java:177)
       at org.jboss.aop.proxy.container.ContainerCache.createContainer(ContainerCache.java:203)
       at org.jboss.aop.proxy.container.ContainerCache.createAndCacheContainer(ContainerCache.java:191)
       at org.jboss.aop.proxy.container.ContainerCache.initClassContainer(ContainerCache.java:164)
       at org.jboss.aop.proxy.container.ContainerCache.initialise(ContainerCache.java:92)
       at org.jboss.aop.proxy.container.ContainerCache.initialise(ContainerCache.java:72)
       at org.jboss.aop.microcontainer.integration.AOPDependencyBuilder.getDependencies(AOPDependencyBuilder.java:99)
       at org.jboss.kernel.plugins.dependency.DescribeAction.installActionInternal(DescribeAction.java:56)


      The issue is that GenericBeanAspectFactory/GenericBeanFactory uses the wrong classloader != not deployment unit's classloader.

      Was this ever tested in JBoss5?
      Or what piece of code/xml am I missing in my demos?

        • 1. Re: MC AOP CL issue
          kabirkhan

          In AS5 it uses a special classpool factory. Try doing

          AspectManager.instance().setClassPoolFactory(new org.jboss.aop.asintegration.jboss5.JBoss5ClassPoolFactory());
          

          as part of your test setup and see if that helps at all.

          I have started revisiting this at the moment, but it will take a while before I am done.

          • 2. Re: MC AOP CL issue
            kabirkhan

            My previous answer is not really related. Is this a standalone example? How can I get the classloader for the aspect? Should I be adding ClassLoaderMD to the BMD on deployment? Once this is this done, I should probably call the wrapped BeanFactory.getClassLoader() from GenericBeanAspectFactory?

            • 3. Re: MC AOP CL issue
              alesj

               

              "kabir.khan@jboss.com" wrote:
              Is this a standalone example?

              Yes.
              See my MC demos project:
              - http://anonsvn.jboss.org/repos/jbossas/projects/demos/microcontainer/trunk/

              "kabir.khan@jboss.com" wrote:

              How can I get the classloader for the aspect? Should I be adding ClassLoaderMD to the BMD on deployment?

              This is already done in BeanMetaDataDpeloyer - if not explicitly set.

              Also, this could be the workaround
               <interceptor xmlns="urn:jboss:aop-beans:1.0" name="StopWatchInterceptor" class="org.jboss.demos.ioc.annotations.StopWatchInterceptor">
               <classloading><inject bean="jboss-demos-ioc:0.0.0"/></classloading>
               </interceptor>
              

              If it wasn't for this issue:
              - http://www.jboss.com/index.html?module=bb&op=viewtopic&t=144593

              "kabir.khan@jboss.com" wrote:

              Once this is this done, I should probably call the wrapped BeanFactory.getClassLoader() from GenericBeanAspectFactory?

              Yeah, probably something like that - perhaps pushing the CL that BMDD sets also to the GenericBeanAspectFactory --> its underlying GenericBeanFactory.

              • 4. Re: MC AOP CL issue
                kabirkhan

                I have commited a fix for this against JBMICROCONT-374. I still need to figure out how to test this...

                • 5. Re: MC AOP CL issue
                  alesj

                   

                  "kabir.khan@jboss.com" wrote:
                  I still need to figure out how to test this...

                  I'll try your fix with my demos - for the initial check.

                  But we should definitely have some tests.
                  JBossAS_testsuite looks like the most appropriate candidate
                  as it has all the pieces already installed == MC + AOP.