`
earls
  • 浏览: 69885 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

奇怪的OSGi-Spring类加载的问题

    博客分类:
  • OSGi
阅读更多
       调试程序时发现一个奇怪的类加载问题,描述如下:
       假设有一个Bundle,其中有类a.A和b.B:
java 代码
 
  1. package a;  
  2.   
  3. public class A{  
  4.     private B ab;  
  5.     public void setB(B b){  
  6.         this.ab = b;  
  7.     }  
  8. }  

以及他们的Spring配置:
xml 代码
 
  1. <bean id="bBean" class="b.B" />  
  2.   
  3. <bean id="aBean"  class="a.A">  
  4.   <property name="b" ref="bBean"/>  
  5. </bean>  

META-INF.MF中仅导出包a。

        现在启动该Bundle,A和B的ClassLoader都是CL1,这是毫无疑问的。但当使用Eclipse的OSGi控制台命令 update 时,问题出现了,会抛出异常“Failed to convert property value of type [b.B] to required type [b.B] for property 'b' ”,这个异常很奇怪,似乎有点自相矛盾。其实不然,update后,由于A所在包属于导出包,可能被其他Bundle共享,所以其ClassLoader仍为CL1,因此A中定义的变量ab的类型B是由CL1加载的,而此时的bBean在初始化时,其ClassLoader却是一个新的实例CL2。因此,虽然bBean和ab的类型都是b.B,由于两者的ClassLoader不同,所以就出现了上面的错误信息。
       这里的关键就是CL2的产生,为什么在update时要新生成一个ClassLoader实例?目前尚不清楚这个Bug属于Eclipse的OSGi控制台的还是OSGi-Spring项目本身,甚至是OSGi规范。请高人帮忙指点迷津。
分享到:
评论
1 楼 earls 2007-08-20  
今天看了一下org.osgi.framework.Bundleupdate方法的API,原来所有导出的类在update时都不能被更新,这也就是其ClassLoader还是原来的那个的缘故。只有调用PackageAdmin.refreshPackages或者整个框架重载时才会更新那些导出的类

相关推荐

    osgi-resource-locator-1.0.1-API文档-中文版.zip

    赠送jar包:osgi-resource-locator-1.0.1.jar; 赠送原API文档:osgi-resource-locator-1.0.1-javadoc.jar; 赠送源代码:osgi-resource-locator-1.0.1-sources.jar; 赠送Maven依赖信息文件:osgi-resource-locator...

    spring-osgi-1.2.1-with-dependencies.zip

    spring-osgi-1.2.1-with-dependencies.zip spring-osgi-1.2.1-with-dependencies.zip spring-osgi-1.2.1-with-dependencies.zip

    spring-osgi-1.2.0-rc1-with-dependencies.zip

    "spring-osgi-1.2.0-rc1"是Spring OSGi的一个早期版本,"RC1"代表Release Candidate 1,意味着这是正式发布前的最后一个测试版本。在这个版本中,开发者可以期待一些新特性和改进,但同时也可能存在一些未发现的...

    osgi-SpringDM

    Spring-DM指的是 Spring ...Spring-DM 的主要目的是能够方便地将 Spring 框架和OSGi框架结合在一起,使得使用Spring的应用程序可以方便简单地部署在OSGi环境中,利用OSGi框架提供的服务,将应用变得 更加模块化。

    spring-osgi-1.2.1.rar

    Spring OSGi是Spring框架与OSGi(Open Service Gateway Initiative)规范相结合的产物,它允许在OSGi容器中使用和管理Spring应用。OSGi是一种Java模块化系统,它提供了动态部署、版本控制和依赖管理等功能,极大地...

    osgi-resource-locator-1.0.1-API文档-中英对照版.zip

    赠送jar包:osgi-resource-locator-1.0.1.jar; 赠送原API文档:osgi-resource-locator-1.0.1-javadoc.jar; 赠送源代码:osgi-resource-locator-1.0.1-sources.jar; 赠送Maven依赖信息文件:osgi-resource-locator...

    spring-osgi-1.2.0-with-dependencies.zip

    spring-osgi-1.2.0-with-dependencies.zip spring-osgi-1.2.0-with-dependencies.zip spring-osgi-1.2.0-with-dependencies.zip

    spring-osgi-1.2.1-with-dependencies

    总结来说,“spring-osgi-1.2.1-with-dependencies”是一个集成了Spring与OSGi的完整包,它提供了在OSGi环境中运行Spring应用所需的所有组件和服务。通过理解和掌握这个包,开发者可以更好地利用OSGi的模块化优势,...

    spring-osgi-1.2.0.zip

    标题"spring-osgi-1.2.0.zip"表明这是一个包含Spring OSGi 1.2.0版本的压缩包。这个版本可能包含了Spring框架与OSGi集成的相关库、文档、示例代码等资源,便于开发者在OSGi环境中使用Spring。 描述中提到"spring1.2...

    killbill-osgi-bundles-lib-slf4j-osgi-0.8.4.zip

    【标题】"killbill-osgi-bundles-lib-slf4j-osgi-0.8.4.zip" 是一个基于OSGi的 Kill Bill 库,其中包含了SLF4J(Simple Logging Facade for Java)的OSGi兼容版本。SLF4J是一个为各种日志框架提供简单抽象的接口,...

    OSGi-lib.rar

    标题"OSGi-lib.rar"暗示这是一个与OSGi相关的库文件集合,可能是为了开发OSGi应用或者研究OSGi技术而准备的资源包。描述中的重复信息"OSGi-lib.rar"可能是由于复制错误,但我们可以推测这个压缩包包含了关于OSGi的...

    Spring Dynamic Modules开发所需全部jar包

    spring-osgi-core-1.2.1.jar spring-osgi-core-1.2.1-sources.jar spring-osgi-extender-1.2.1.jar spring-osgi-extender-1.2.1-sources.jar spring-osgi-io-1.2.1.jar spring-osgi-io-1.2.1-sources.jar spring-...

    spring-osgi-1.2.1-javadoc.chm

    自制CHM版的API文档,带索引。 注:如果各位下载后打开或无法显示页面,请在CHM文件右键—属性—解除锁定即可。

    osgi-tutorial.zip

    **正文** ...最后,`osgi-tutorial`这个压缩包可能包含了逐步指导如何进行上述操作的文档、代码示例和练习。通过学习和实践这些内容,你可以深入理解OSGi和Spring的集成,提升你的企业级应用开发技能。

    carrot-osgi-anno-scr-make-2.0.1.zip

    《Carrot-OSGi-Annotation-SCR-Make:探索开源项目的OSGI服务组件构建》 在软件开发领域,OSGi(Open Services Gateway Initiative)是一种模块化系统和Java应用程序框架,它使得开发者能够创建可独立更新和重用的...

    spring-dm-osgi整合jar包

    2. Spring DM库:如`spring-osgi-core`, `spring-osgi-io`, `spring-osgi-extender`等,提供了与OSGi环境交互的接口和工具。 3. OSGi框架库:如`org.eclipse.osgi`,这是实现OSGi规范的实现,例如Equinox或Felix。 4...

    ftpserver-osgi-spring-service-1.0.2.jar

    实测可用

    ftpserver-osgi-spring-service-1.0.1.jar

    实测可用

    ftpserver-osgi-spring-service-1.0.4.jar

    实测可用

    ftpserver-osgi-spring-service-1.0.3.jar

    实测可用

Global site tag (gtag.js) - Google Analytics