`
xmong
  • 浏览: 261669 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

OSGI+SpringDM+Hessian

阅读更多
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
分享到:
评论
2 楼 xmong 2013-01-23  
deeplyloving 写道
请问楼主访问路径是什么?


这几天忙项目,没怎么看博客,加了一下访问路径可见 “2.5.3 测试服务 ”。
顺便找了一下,将项目的所有插件都上共享了。
1 楼 deeplyloving 2013-01-07  
请问楼主访问路径是什么?

相关推荐

    osgi+maven+springdm文档集

    **OSGI MAVEN SPRINGDM 文档集** 这个文档集主要涵盖了三个关键的Java开发技术:OSGI(Open Service Gateway Initiative)、Maven以及Spring Dynamic Modules(Spring DM)。这些技术都是现代Java开发中的重要组成...

    OSGi+SpringMVC+Spring+Hibernate企业应用框架

    辛苦研究了一个多月,终于搭建成了一个可用于实际应用开发的OSGI-WEB框架,采用OSGi+SpringMVC+Spring+Hibernate+Virgo技术,鉴于此类技术架构甚少,特提供出来供大家参考。 使用步骤: 一、下载STS搭建Osgi开发...

    学习SpringDM+OSGI的总结

    ### SpringDM与OSGI概述 #### OSGI概念解析 OSGI(Open Service Gateway Initiative),直译为“开放的服务网关初始化”,它是一系列针对Java动态化模块化系统的规范。OSGI不仅指代一个官方联盟,还代表着由该联盟...

    Pro+Spring+Dynamic+Modules+for+OSGi+Service+Platforms

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

    SpringDM笔记31-Testing with OSGi and SpringDM

    标题 "SpringDM笔记31-Testing with OSGi and SpringDM" 涉及到的是在OSGi环境中使用SpringDM进行测试的相关知识。OSGi(Open Service Gateway Initiative)是一种Java模块化系统,允许动态地发现、加载和卸载服务。...

    OSGi与Spring:Spring DM开发

    ### OSGi与Spring:Spring DM开发环境配置详解 #### 一、引言 随着软件架构的不断发展,模块化和微服务化的趋势日益明显。在Java领域,OSGi(Open Service Gateway Initiative)作为一套成熟的技术标准,为实现模块...

    OSGI+MySql增删改查

    MyEclipse10+Jdk1.7+OSGI+MySql实现数据库的增删改查对应的源码,详细操作请参考http://blog.csdn.net/xqf222/article/details/41281217

    osgi-SpringDM

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

    OSGI + Webservice 例子

    OSGI(Open Services Gateway Initiative)是一种开放标准,用于创建模块化和可扩展的Java应用程序。它提供了一种灵活的框架,允许开发人员将应用程序分解为独立的模块,这些模块称为服务。OSGI的核心是它的模块系统...

    osgi_spring_dm_jr

    标题中的"osgi_spring_dm_jr"可能是指OSGi(Open Service Gateway Initiative)框架下,Spring Dynamic Modules(Spring DM)的Java Runtime环境相关的知识。OSGi是一种模块化系统,用于构建可升级、可扩展和可配置...

    基于OSGi和Spring开发Web应用.doc

    3. Spring-DM:Spring-DM 是 Spring 开发组织在 2008 年发布的,将 OSGi 和 Spring 结合的第一个版本。 4. dm Server:dm Server 是一个完全模块化部署的基于 OSGi 的 Java 服务器,为运行企业 Java 应用和 Spring ...

    SpringDM笔记7-开发SpringDM Bundle

    SpringDM(Spring Dynamic Modules)是Spring框架的一个扩展,专门用于OSGi(Open Service Gateway Initiative)环境中的应用程序开发。OSGi是一种Java模块化系统,它允许开发者将应用程序拆分成独立的、可热插拔的...

    未来10年:OSGi、Spring_DM

    ### 未来10年:OSGi、Spring_DM #### OSGi—模块化与动态性的终结者 **JavaEE开发及部署模型的局限性** 在JavaEE开发与部署的过程中,存在不少挑战,主要包括研发挑战、部署挑战以及维护挑战。这些挑战主要体现在...

    OSGI+Specification+r4.core

    综上所述,“OSGi+Specification+r4.core”不仅详细阐述了OSGi R4的核心规范及其对现代企业级应用的重要性,还明确了版权许可范围,确保了技术社区的健康有序发展。对于开发者和企业而言,理解并应用这些规范能够...

    基于spring dm server 的osgi 例子

    【标题】:“基于Spring DM Server的OSGi实例” 在IT领域,OSGi(Open Services Gateway Initiative)是一种模块化系统和Java服务平台,它允许开发者创建可热插拔的组件,从而提高了软件的可维护性和可扩展性。...

    osgi&spring规范

    Spring DM(Dependency Management)项目(现在称为Spring OSGi)为在OSGi环境中使用Spring提供了便利。它允许Spring的应用程序组件以模块化方式部署,并且能利用OSGi的服务注册和发现机制。 Spring在OSGi中的主要...

    基于virgo环境的OSGI+Maven的web开发代码下载(spring+hibernate+GWT)

    标题中的“基于virgo环境的OSGI+Maven的web开发代码下载”表明这是一个使用OSGi(模块化Java系统)和Maven构建的Web应用程序项目,运行在Virgo服务器上。Virgo是SpringSource推出的一个OSGi应用服务器,它支持Spring...

Global site tag (gtag.js) - Google Analytics