Page 1 of 3 123 LastLast
Results 1 to 10 of 22

Thread: Aspectj Weaving JPA- In Standalone Equinox

  1. #1

    Default Aspectj Weaving JPA- In Standalone Equinox

    I'm trying to deploy a bundle using AspectJ Weaving with JPA in a standalone Equinox instance. But I can't seem to activate the weaver, I've tried various approaches but each time I get the following error:
    Code:
    17:23:26.329 [SpringOsgiExtenderThread-5] ERROR o.s.o.c.s.OsgiBundleXmlApplicationContext - Pre refresh error
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.context.weaving.AspectJWeavingEnabler#0': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'loadTimeWeaver': Initialization of bean failed; nested exception is java.lang.IllegalStateException: ClassLoader [org.springframework.osgi.util.BundleDelegatingClassLoader] does NOT provide an 'addTransformer(ClassFileTransformer)' method. Specify a custom LoadTimeWeaver or start your Java virtual machine with Spring's agent: -javaagent:spring-agent.jar
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:478)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
    	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
    	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:220)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
    	at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:881)
    	at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:534)
    	at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.access$800(AbstractDelegatedExecutionApplicationContext.java:54)
    	at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext$3.run(AbstractDelegatedExecutionApplicationContext.java:227)
    	at org.springframework.osgi.util.internal.PrivilegedUtils.executeWithCustomTCCL(PrivilegedUtils.java:85)
    	at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.startRefresh(AbstractDelegatedExecutionApplicationContext.java:195)
    	at org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor.stageOne(DependencyWaiterApplicationContextExecutor.java:228)
    	at org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor.refresh(DependencyWaiterApplicationContextExecutor.java:179)
    	at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.refresh(AbstractDelegatedExecutionApplicationContext.java:137)
    	at org.springframework.osgi.extender.internal.activator.ContextLoaderListener$2.run(ContextLoaderListener.java:741)
    	at java.lang.Thread.run(Thread.java:595)
    Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'loadTimeWeaver': Initialization of bean failed; nested exception is java.lang.IllegalStateException: ClassLoader [org.springframework.osgi.util.BundleDelegatingClassLoader] does NOT provide an 'addTransformer(ClassFileTransformer)' method. Specify a custom LoadTimeWeaver or start your Java virtual machine with Spring's agent: -javaagent:spring-agent.jar
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:478)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
    	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
    	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:220)
    The bundle's descriptor is using <context:load-time-weaver aspectj-weaving="on"/> and as suggested, I've tried adding the -javaagent:spring-agent.jar when I start-up Equinox, here are a few attempts that have failed:
    Code:
    java -javaagent:spring-agent.jar -jar org.eclipse.osgi_3.5.0.v20080804-1730.jar  -console
    
    java -Xbootclasspath/a:aspectjweaver.jar -javaagent:spring-agent.jar -jar org.eclipse.osgi_3.5.0.v20080804-1730.jar  -console
    
    java -javaagent:org.springframework.instrument-2.5.4.A.jar -jar org.eclipse.osgi_3.5.0.v20080804-1730.jar  -console
    
    java -Xbootclasspath/a:aspectjrt.jar,pectjweaver.jar,spring-agent.jar -javaagent:spring-agent.jar -jar org.eclipse.gi_3.5.0.v20080804-1730.jar  -console
    Anyone else had a similar experience loading a bundle using aspectj ?
    Do I need to add Spring-DM or some other library in order for the spring-agent.jar to be detected ?

  2. #2

    Default

    You can try to add -Dosgi.parentClassloader=app to the jvm parameter.

    This is probably a problem with the visibility of the javaagent in the different bundle classloaders. I haven't figured out yet how you can propagate the
    javaagent to the other bundles.

    efh

  3. #3
    Join Date
    Jun 2007
    Location
    Nantes, France
    Posts
    44

    Default

    Hi,

    I'm facing exactly with the same error and Google only returned this post as a reference.
    Have you managed to fix it ?
    EscapeK - http://www.escapek.org - Open source project for IT ecosystem management

  4. #4

    Default

    Quote Originally Posted by Nico View Post
    Hi,

    I'm facing exactly with the same error and Google only returned this post as a reference.
    Have you managed to fix it ?
    Hmm I've spent very little time on this problem but it seems to me that javaagent approach will not work in equinox apps.

    There is the equinox aspects project that enables LTW in equinox environment but it has problems.

    I have traced issue to the org.springframework.instrument.classloading.Instru mentationLoadTimeWeaver and I guess that spring LTW could be integrated with equinox aspects if someone writes correct LoadTimeWeaver (in my case everything blows somewhere in addTransformer method).

    I guess that it has something to do with https://bugs.eclipse.org/bugs/show_bug.cgi?id=248047
    Last edited by iloncar; Apr 14th, 2009 at 06:02 PM.

  5. #5
    Join Date
    Sep 2008
    Location
    Hamburg, Germany
    Posts
    1,637

    Default

    The link to the bugzilla entry of Equinox Aspects is absolutely correct. I briefly looked at this and think it is possible to implement a small bridge between Equinox Aspects and the LoadTimeWeaver infrastructure of Spring, but I haven't found the time to actually implement it.

    If anybody out there would like to volunteer, I would be happy to assist and provide some guidance through Equinox Aspects, otherwise I will look at this in more depth within the next weeks and post my results.

  6. #6
    Join Date
    Sep 2008
    Location
    Hamburg, Germany
    Posts
    1,637

    Default

    Does anybody have a small example project to reproduce the problem? That would be highly appreciated - and would speed up solving this issue... :-)

    Feel free to send me a zipped project for my workspace via email (lippert@acm.org).

  7. #7

    Default

    Quote Originally Posted by mlippert View Post
    Does anybody have a small example project to reproduce the problem? That would be highly appreciated - and would speed up solving this issue... :-)

    Feel free to send me a zipped project for my workspace via email (lippert@acm.org).
    Hi Martin! Thank you very much for your work on equinox aspects. It helped us a lot. I don't know how would we manage those change listeners if there were no aspects.

    I will try to assemble an example during the weekend.

  8. #8
    Join Date
    Jun 2007
    Location
    Nantes, France
    Posts
    44

    Default

    Copy of the email sent to mlippert:
    Hi Martin,

    As you requested on this forum thread, I send you an eclipse project to reproduce the problem. To run it, I used the standard equinox platform package, with Eclipse Link 1.1 bundles installed. I've also installed the project dependencies from pom.xml using the command: mvn -e eclipse:install-plugins -DeclipseDir=/path/to/equinox/
    Then I used this platform in eclipe as the target platform for the project and created a run configuration.
    When I run this platform, I can reproduce the error stack described on the thread. Note that to be able to run, this project has a reference to a SQL datasource defined in osgi-context.xml. You will add to provide another bundle which exports such a service.
    Hope this help. Let me know I you have problems using this sample project.

    Regards,

    Nicolas.
    Attached Files Attached Files
    EscapeK - http://www.escapek.org - Open source project for IT ecosystem management

  9. #9
    Join Date
    Sep 2008
    Location
    Hamburg, Germany
    Posts
    1,637

    Default

    Thank you guys for the examples. I made some progress on this. Let me explain what the current status is.

    I implemented an EquinoxAspectsLoadTimeWeaver that can be used instead of InstrumentingLoadTimeWeaver or similar things from Spring as the load-time weaver for a specific bundle. This EquinoxAspectsLoadTimeWeaver uses the Equinox Aspects infrastructure to modify bytecode at load-time. This works pretty fine. I tested this with the @Configurable stuff from spring-aspects and it works. Since it implements the LoadTimeWeaver interface of Spring, I hope that all the other things that uses this load-time weaving integration of Spring (JPA weaving etc.) will work as well. Haven't tested all the other use-cases at the moment.

    Nevertheless (especially for the AspectJ weaver) there are some issues with this solution:

    1. You need to start the bundle that uses this load-time weaver before any other bundle accesses it (via config.ini, p2, startlevel, whatever). Using the Lazy-Start works only partially. The problem with Lazy-Activation is that it activates the bundle when the first class is loaded. As a reaction to this Spring loads and initializes the spring context for this bundle, which then initializes the load-time weaver for this bundle (as defined in the context definition). That means also, that the first class is loaded and AFTER that the context is initialized. Therefore the first class that gets loaded is not woven. If this is your view, for example, that got loaded because of the extension being created, your view class is not woven (when its the first class from that bundle).
    This is a problem at the moment and I have no clue how to solve this in a generic way. You can workaround this by starting those bundles manually or automatically, NOT using Lazy-Activation.

    2. The second problem is the spring-aspects bundle. The AspectJ weaver of spring configures itself by loading the aop.xml files from the classpath. The spring-aspects bundle does not export the aop.xml file. Therefore its not accessible to other bundles via normal classloader resource loading. You can fix this by adding "META-INF" to the list of exported packages in the MANIFEST.MF of the spring-aspects bundle, but you need to modify that bundle.

    So far the details about my investigations at the moment... Let me know if you would like to try that out! I am happy to get feedback on this.

  10. #10

    Default

    Quote Originally Posted by mlippert View Post
    Thank you guys for the examples. I made some progress on this. Let me explain what the current status is.
    Great news Martin!

    Nevertheless (especially for the AspectJ weaver) there are some issues with this solution:

    1. You need to start the bundle that uses this load-time weaver before any other bundle accesses it (via config.ini, p2, startlevel, whatever). Using the Lazy-Start works only partially. The problem with Lazy-Activation is that it activates the bundle when the first class is loaded. As a reaction to this Spring loads and initializes the spring context for this bundle, which then initializes the load-time weaver for this bundle (as defined in the context definition). That means also, that the first class is loaded and AFTER that the context is initialized. Therefore the first class that gets loaded is not woven. If this is your view, for example, that got loaded because of the extension being created, your view class is not woven (when its the first class from that bundle).
    This is a problem at the moment and I have no clue how to solve this in a generic way. You can workaround this by starting those bundles manually or automatically, NOT using Lazy-Activation.

    Is it possible to implement equinox hook (extender) to force context initialization of spring enabled budle before first class is loaded?

    2. The second problem is the spring-aspects bundle. The AspectJ weaver of spring configures itself by loading the aop.xml files from the classpath. The spring-aspects bundle does not export the aop.xml file. Therefore its not accessible to other bundles via normal classloader resource loading. You can fix this by adding "META-INF" to the list of exported packages in the MANIFEST.MF of the spring-aspects bundle, but you need to modify that bundle.

    So far the details about my investigations at the moment... Let me know if you would like to try that out! I am happy to get feedback on this.

    I would really like to try this. Can you post the code?

    Should we open JIRA issue to make aop.xml pubicly exposed?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •