分享

problems using Spring with Eclipse RCP

 LibraryPKU 2014-05-20
  • problems using Spring with Eclipse RCP

    My team provides backend data support for an Eclipse RCP/Equinox GUI. Previously, we have managed our dependency injection using Guice. We are switching to Spring Framework 3.x for DI and have encountered problems coaxing the Spring jars to "co-operate" with our data layer jars when running the GUI application. We have searched the forums here and also the Java Forums at the Big Moose Saloon, but have not found any possible solutions.

    Our initial approach was to copy OSGI ready spring jars into our Target Platform directory, and add each of the spring dependencies (org.springframework.beans-3.1.3.RELEASE.jar, org.springframework.context-3.1.3.RELEASE.jar) as Eclipse Registered buddies to our applicaton jars. When we did that, we got this error when Spring tries to load our DataControllerModule, which is annotated with @Configuration and instantiates our beans:

    Code:
    GUI studio error:
    org.springframework.beans.factory.BeanDefinitionStoreException: Failed to load bean class: com.foo.datacontroller.internal.DataControllerModule; nested exception is java.io.FileNotFoundException: class path resource [com/foo/datacontroller/internal/DataControllerModule.class] cannot be opened because it does not exist
    	at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:293)
    	at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:227)
    	at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:623)
    	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:454)
    The next thing that we tried was to create one big jar with all the spring dependencies in it, create a MANIFEST.MF file in that jar that exports all the individual packages needed from the spring jars, and reference this single "bundle" as an eclipse buddy in our applicaton jars. That works, in that we no longer see the FileNotFoundExceptions. However, some of the Spring-related Import-Package references have to be manually edited in our application jars. For example, the big spring jar exports "org.springframework.beans.factory.annotation" without version information while our application jar is looking for an import matching org.springframework.beans.factory.annotation;versi on="(3.1,4]" with version information. Until we edit out the version information, this appears as Missing Constraint in Eclipse.

    We think there must be an easier way to get our jars working with Spring OSGI jars in our GUI, but we are stumped at the moment. We would be grateful if a forum member could point us to some relevant documentation that might help us sort out the classloader relationships, or even tell us we are barking up the wrong tree if that is the case. Thank you in advance for your time.
    Last edited by rcurry; Feb 28th, 2013, 01:27 PM. Reason: formatting
  • #2
    There is one other thing that we tried, and that was using this same big jar needed for the OSGI environment as a maven dependency in our application jars. We thought that might allow us to skip the part of manually editing out the version information on packages. However, while the spring jars in the big jar are available on the OSGI bundle classpath, they are not available on the regular classpath if we try to use that jar to supply our Spring dependencies in a maven build.
  • #3
    One thing that we just got to work was to create the "big jar" as an exploded bundle. The jar then contains class files and not a set of jars. This works fine in the OSGI environment, and we can build our application projects against it using maven. We still had a couple of transitive dependencies showing up in the Import-Packages section of the MANIFEST. We were able to exclude these using
    Code:
    <configuration>
      <instructions>
        <Import-Package>!org.springframework.context.annotation;version="[3.1,4)",*"</Import-Package>
      </instructions>
    </configuration>
    in the "maven-bundle-plugin" section of our pom.xml file.
    Last edited by rcurry; Mar 1st, 2013, 12:44 PM. Reason: formatting
  • #4
    Hey!

    Maybe the Eclipse Gemini Blueprint project can help here (it is the successor of Spring Dynamic Modules, the addition to Spring to use it in an OSGi environment): http://www./gemini/blueprint/

    The work that I did with Spring in an Eclipse RCP environment is too long ago to be still valid, but I remember that I used Spring Dynamic Modules. And for doing dependency injection into Eclipse extensions, I implemented this a long time ago:
    https://github.com/martinlippert/spr...ension-factory

    HTH,
    -Martin
  • #5
    Thank you, Martin.

    We have had a couple of discussions about whether or not Gemini Blueprint might be what we need. I will take a look at the code you shared. If there is something there that helps with our situation, I will be sure and update this thread.

    Regards,

    rcurry


  • HTH,
    -Martin
    Thank you so much! You did the nice work for us!

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多