论坛首页 Web前端技术论坛

RAP整合Spring(基于Spring-osgi)--> 源码及录像下载

浏览 5688 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2009-01-11   最后修改:2009-01-12

RAP 整合 Spring (基于 Spring-osgi

 

 

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

   发表时间:2009-01-11  
刚刚录制了一段录像,包含了上面的操作,为了使录像文件足够的小,操作有点快,请见谅.


注: 文件格式是.exe的,为了能够上传, 我改了名字, 大家下载后, 需要改成.exe后缀.
  • RapSpringOsgi.rar (6 MB)
  • 描述: 具体操作的录像文件,需要改成.exe后缀
  • 下载次数: 510
0 请登录后投票
   发表时间:2009-01-11  
录像文件 需要进入论坛看贴子才可以下载, blog不可以下载.

这个是论坛的地址http://www.iteye.com/topic/314666

经测试, 下载后的录像是可以观看的.
0 请登录后投票
   发表时间:2009-01-11   最后修改:2009-01-11
谢谢。
我正在学习 spring osgi。
希望能多一些 osgi web 的介绍,及在tomcat中部署的说明。
0 请登录后投票
   发表时间:2009-03-02  
经测试, 下载后的录像是可以观看的
0 请登录后投票
论坛首页 Web前端技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics