`
snoopy7713
  • 浏览: 1140288 次
  • 性别: Icon_minigender_2
  • 来自: 火星郊区
博客专栏
Group-logo
OSGi
浏览量:0
社区版块
存档分类
最新评论

RAP 整合 Spring (基于 Spring-osgi )

    博客分类:
  • RAP
阅读更多

RAP 介绍请见: http://www.eclipse.org/rap/

Spring 介绍请见: http://www.springsource.org/

Spring-osgi 介绍请见: http://www.springsource.org/osgi

 

RAP 也是完全的基于 OSGI ,只要对于 osgi 的概念以及 Spring-osgi 的具体用法能够完全理解的话,那么这里所谓的 RAP 整合 Spring ,就和网上常见的 OSGI 整合 Spring 没什么大的区别了。

 

Spring-osgi 就是在 Spring 的基础上,使得在 osgi 环境下也能够使用 Spring osgi 下单 bundle 有其自己的生命周期, Spring-osig 需要相互注入分布在多个 bundle 间的 bean ,而这些 bean 又和自身所在的 bundle 拥有一致的生命周期。那么 Spring-Osgi 需要解决的难题正是 classloader 问题,以及将分布在不同生命周期的 bundle bean 以一定的模式整合在一起(也就是所谓的注入, bean 的依赖关系)。

 

第一步 :下载 Spring ,下载 Spring-osgi

       将下载的 Spring-osig 下的 dist lib 下的所有 jar 放到 Eclipse RAP target 下。

      

       需要注意的问题 Spring-osgi lib 内包含了一个 org.eclipse.osgi 包,同时 Eclipse RAP target 下也包含了一个 org.eclipse.osgi 包,由于 Spring-osig 提供的 org.eclipse.osgi 版本更新,你可以将原来 EclipseRap Target 下的 org.eclipse.osgi 包删除(也就是选择版本低的删除即可)。     

 

第二步 :创建基本的 RAP 项目

使用 EclipseRAP 提供的模板创建一个 mail 的项目。

需要注意的问题:需要选择基于 Eclipse ,添加 Activator ,这样点击‘下一步‘后,才可以选择 RAP 提供的几个模板来创建项目。

 

第三步 :创建 server 项目,创建 server.impl 项目

这里所谓的 server 项目,指的是: model bo vo ), service interface

server.impl 项目,指的是: service interface 的实现。

 

server 项目内容比较少,具体内容见代码:

public interface IDemoService {

    public void sayHello();

}

 

server.impl 项目中 .具体内容见代码:

public class DemoService implements IDemoService {

    public void sayHello() {

       System. out .println( "Hello OSGI" );

    }

}

 

 

META-INF 文件下为 spring 创建一个 xml 文件 (xml 文件名称任意 ).

       具体内容见代码 :

    < bean id = "demoService" scope = "bundle" class = "lggege.rap.demo.server.impl.DemoService" >

    </ bean >

    < osgi:service ref = "demoService" interface = "lggege.rap.demo.server.IDemoService" />

 

第四步 RAP 调用 implement 中的服务

<!---->1.       <!----> launch 中的 Activator BundleContext 对外暴露,具体内容见代码:

public class Activator extends AbstractUIPlugin {

    private BundleContext context ;

    public void start(BundleContext context) throws Exception {

       super .start(context);

       plugin = this ;

       this . context = context;

    }

    public BundleContext getContext() {

       return context ;

    }

    // .. 省略其他代码

}

 

<!---->2.       <!---->这步就比较简单了,就是在 RAP 的某个控件的添加一个 listener ,通过从 bundleContext 中使用 Service interface class 来获得服务。

       我是为 MessagePopupAction 添加了 listener, 具体内容见代码:

 

    public void run() {

//        MessageDialog.openInformation(window.getShell(), "Open", "Open Message Dialog!");

    ServiceReference serviceReference = Activator.getDefault ().getContext().getServiceReference(IDemoService. class .getName());

    IDemoService demoService = (IDemoService) Activator.getDefault ().getContext().getService(serviceReference);

    demoService.sayHello();

}

 

第五步 :运行

       需要在 run 中添加 spring-osgi 对应的几个 bundle 即可。进入 RAP 后,点击特定的控件去触发事件,通过在事件中调用外部的服务。

       具体效果:控制台看到信息输出 .

 

第六步 :分析

就这么简单,通过使用 Spring-osgi ,我们能够通过配置的方式往 osgi 注册服务,这个服务是来自于 Spring 配置的 bean RAP 通过从 BuncleContext Service interface 来获得服务。

 

 

后续文章的内容:

RAP 整合 Spring (基于 Spring-osgi )可下载源码和视频 URL:http://lggege.iteye.com/blog/314666
spring-osgi配置log4j(创建fragment project) 可下载视频 URL:http://lggege.iteye.com/blog/314874
Spring-osgi整合iBATIS 可下载代码和视频 URL:http://lggege.iteye.com/blog/315257

分享到:
评论

相关推荐

    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,意味着这是正式发布前的最后一个测试版本。在这个版本中,开发者可以期待一些新特性和改进,但同时也可能存在一些未发现的...

    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-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...

    spring-osgi-1.2.1.rar

    - Spring应用可以被包装成OSGi bundle,同时保持原有的XML配置或基于注解的配置方式。 3. **Spring DM (Dependency Manager)** - Spring OSGi早期版本使用Spring DM(Dependency Manager),它是Spring 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.0.zip

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

    基于java的开发源码-OSGi 分布式通讯组件 R-OSGi.zip

    基于java的开发源码-OSGi 分布式通讯组件 R-OSGi.zip 基于java的开发源码-OSGi 分布式通讯组件 R-OSGi.zip 基于java的开发源码-OSGi 分布式通讯组件 R-OSGi.zip 基于java的开发源码-OSGi 分布式通讯组件 R-OSGi.zip ...

    spring-osgi-1.2.1-javadoc.chm

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

    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整合 计算器例子(转) +附整合代码和spring-osgi核心jar

    标题中的“Spring与OSGI整合 计算器例子(转) +附整合代码和spring-osgi核心jar”表明我们将探讨如何将Spring框架与OSGi(Open Services Gateway Initiative)模块化系统进行集成,并通过一个计算器的例子来说明这个...

    osgi-SpringDM

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

    OSGI整合Spring、Mybatis、Spring MVC实现一个登录应用案例

    文件"osgi-tutorial"很可能是这个案例的源代码,包含所有必要的配置文件、Java源代码和资源。分析这个源码,我们可以深入理解OSGI环境下这些组件如何协同工作,以及如何在实际项目中实现类似的功能。 总的来说,这...

    spring-osgi.jar及其依赖包

    Spring OSGi是Spring框架与OSGi(Open Service Gateway Initiative)规范集成的产物,它使得在OSGi环境中使用Spring变得更加方便。OSGi是一种模块化系统,用于Java应用程序,提供了动态服务发现、版本控制和依赖管理...

    spring osgi相关资源

    2. spring-osgi-extender:实现了Spring DM的功能,使Spring应用能在OSGi环境中运行。 3. spring-osgi-io:提供I/O服务,如网络、文件系统访问等,适应OSGi的隔离环境。 4. 依赖库:包括了对Apache Felix或Equinox等...

    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是一个为各种日志框架提供简单抽象的接口,...

Global site tag (gtag.js) - Google Analytics