OSGI+SpringDM+Hessian
目录
1 简介 1
1.1 OSGI 1
1.2 SPRINGDM 1
1.3 HESSIAN 1
2 OSGI+SPRINGDM+HESSIAN 1
2.1 环境说明 1
2.2 创建服务组件 2
2.3 WEB配置 2
2.4 服务端实现 3
2.4.1 创建服务接口 3
2.4.2 实现服务接口 3
2.4.3 实现服务配置 3
2.5 客户端实现 4
2.5.1 创建客户端 4
2.5.2 实现客户端配置 5
1 简介
1.1 OSGI
OSGI(Open Service Gateway Initiative):面向Java的动态模型系统(The Dynamic Module System For Java)。
1.2 SpringDM
SpringDM(Spring Dynamic Modules):Spring DM的主要目的就是能够方便地将Spring和OSGI框架结合在一起。
1.3 Hessian
Hessian:Hessian是一个轻量级的remoting onhttp工具,使用简单的方法提供了RMI的功能. 相比WebService,Hessian更简单、快捷。
2 OSGI+SpringDM+Hessian
2.1 环境说明
Eclipse3.5以上版本:Eclipse开发工具。
SpringDM1.2.1:从Spring网站下载SpringDM包。在dist和lib目录下导入Spring和OSGI组件:
com.springsource.org.aopalliance
org.springframework.aop
org.springframework.beans
org.springframework.context
org.springframework.core
org.springframework.web
org.springframework.web.servlet
com.springsource.javax.servlet
org.springframework.osgi.core
org.springframework.osgi.extender
org.springframework.osgi.io
org.springframework.osgi.web
org.springframework.osgi.web.extender
org.springframework.osgi.jasper.osgi
org.springframework.osgi.jsp-api.osgi
com.springsource.org.apache.commons.logging
org.springframework.osgi.catalina.osgi
org.springframework.osgi.catalina.start.osgi
com.springsource.com.caucho
有些组件在SpringDM中没有,可以到相应的网站上下载。
2.2 创建服务组件
在Eclipse中新建Plug-in Project工程(名为HessianService),该组件需要向外提供web服务需要创建成为web工程,在项目中创建WEB-INF目录,并在该目录下创建web.配置文件web.xml,Spring bean配置文件applicationContext.xml,OSGI servlet服务配置文件osgi-console-servlet.xml。
如下图所示:
2.3 Web配置
<context-param>
<param-name>contextClass</param-name>
<param-value>org.springframework.osgi.web.context.support.OsgiBundleXmlWebApplicationContext</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>osgi-console</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextClass</param-name>
<param-value>org.springframework.osgi.web.context.support.OsgiBundleXmlWebApplicationContext</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>osgi-console</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
2.4 服务端实现
2.4.1 创建服务接口
package com.hessian.service;
public interface HessianService {
public String getString();
}
2.4.2 实现服务接口
package com.hessian.service.impl;
import com.hessian.service.HessianService;
public class HessianServiceImpl implements HessianService{
@Override
public String getString() {
return "------hessian-service-----";
}
}
2.4.3 实现服务配置
在Spring bean配置文件applicationContext.xml中配置服务实现。
<bean id="hessianServiceImpl" class="com.hessian.service.impl.HessianServiceImpl"></bean>
在OSGI servlet服务配置文件osgi-console-servlet.xml中配置hessian服务。
<bean name="/hessianService" class="org.springframework.remoting.caucho.HessianServiceExporter">
<property name="service" ref="hessianServiceImpl"/>
<property name="serviceInterface">
<value>
com.hessian.service.HessianService
</value>
</property>
</bean>
2.5 客户端实现
2.5.1 创建客户端
package com.hessian.client;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;
import com.hessian.service.HessianService;
public class HessianClient extends AbstractController{
HessianService hessianClientService;
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest arg0,
HttpServletResponse arg1) throws Exception {
System.out.println("hessianService:"+hessianClientService.getString());
return null;
}
public HessianService getHessianClientService() {
return hessianClientService;
}
public void setHessianClientService(HessianService hessianClientService) {
this.hessianClientService = hessianClientService;
}
}
2.5.2 实现客户端配置
在Spring bean配置文件applicationContext.xml中配置Hessian服务调用bean。
<bean id="hessianClientService" class="org.springframework.remoting.caucho.HessianProxyFactoryBean">
<property name="serviceUrl" value="http://localhost:8080/HessianService/hessianService"/>
<property name="serviceInterface" value="com.hessian.service.HessianService"/>
</bean>
在OSGI servlet服务配置文件osgi-console-servlet.xml中配置hessian客户端。
<bean name="/hessianClient" class="com.hessian.client.HessianClient">
<property name="hessianClientService" ref="hessianClientService"></property>
</bean>
2.5.3 测试服务
访问地址:http://localhost:8080/HessianService/hessianClient
服务器输出:hessianService:------hessian-service-----
证明客户端服务服务器端服务成功。
- 大小: 6.5 KB
分享到:
相关推荐
里面有好几个文档,是我自己在研究的时候用到的,还不错,给大家分享下
辛苦研究了一个多月,终于搭建成了一个可用于实际应用开发的OSGI-WEB框架,采用OSGi+SpringMVC+Spring+Hibernate+Virgo技术,鉴于此类技术架构甚少,特提供出来供大家参考。 使用步骤: 一、下载STS搭建Osgi开发...
学习SpringDM+OSGI的一些总结,自我学习,上传文档防止丢失。
for OSGi (Spring-DM) fulfills this role. I first learned about OSGi when the Eclipse IDE started using it in its plug-in architecture. At the time, the versioning and modularity features seemed nicer ...
OSGI + Webservice 例子 新手入门的例子
osig与spring:springDM开发环境配置,eclipse配置osgi开发环境,及命令
OSGi+Technology.rar OSGi+Technology.rar
OSGI+Specification+r4.core
MyEclipse10+Jdk1.7+OSGI+MySql实现数据库的增删改查对应的源码,详细操作请参考http://blog.csdn.net/xqf222/article/details/41281217
Spring-DM指的是 Spring ...Spring-DM 的主要目的是能够方便地将 Spring 框架和OSGi框架结合在一起,使得使用Spring的应用程序可以方便简单地部署在OSGi环境中,利用OSGi框架提供的服务,将应用变得 更加模块化。
NULL 博文链接:https://springsfeng.iteye.com/blog/1271565
osgi springdm.pdf
关于OSGi当前流行技术的介绍,是OSGi入门首选~~
osgi_spring_dm_jrosgi_spring_dm_jrosgi_spring_dm_jrosgi_spring_dm_jrosgi_spring_dm_jr
java 未来10年:OSGi、Spring_DM
基于OSGi和Spring开发Web应用
osgi+vs2010+qt5.11 谢了几个 常用的 插件之间的 通信实例,内有源代码
这个版本是OSGi服务平台规范的第四个版本,由OSGi成员公司的代表共同开发完成,这个版本将原来的API扩展到了新的领域,修正了部分现有的API,以前的应用可以直接运行在新版本的框架中。
比较好的OSGi学习教程,分享给大家,简单易学...。。。