Hessian 示例
来源:互联网 发布:js offsetparent属性 编辑:程序博客网 时间:2024/04/28 19:16
Hessian是caucho公司开发的一种基于二进制RPC协议(Remote Procedure Call protocol)的轻量级远程调用框架
1、web.xml中新增servlet
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"><display-name>Archetype Created Web Application</display-name><welcome-file-list><welcome-file>index.jsp</welcome-file></welcome-file-list><listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener><context-param><param-name>contextConfigLocation</param-name><param-value>classpath:/spring-hessian.xml</param-value></context-param><!-- 整合Spring实现 --><servlet><servlet-name>hello</servlet-name><servlet-class>org.springframework.web.context.support.HttpRequestHandlerServlet</servlet-class></servlet><servlet-mapping><servlet-name>hello</servlet-name><url-pattern>/hello</url-pattern></servlet-mapping><!-- 不整合Spring实现 --><servlet><servlet-name>hi</servlet-name><servlet-class>com.caucho.hessian.server.HessianServlet</servlet-class><init-param><param-name>home-class</param-name><param-value>com.sky.learn.impl.HelloServiceImpl</param-value></init-param><init-param><param-name>home-api</param-name><param-value>com.sky.learn.inf.HelloService</param-value></init-param></servlet><servlet-mapping><servlet-name>hi</servlet-name><url-pattern>/hi</url-pattern></servlet-mapping></web-app>2、整合Spring方式,需添加bean
bean的name必须与servlet的name一致,本例中为hello
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:cache="http://www.springframework.org/schema/cache" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd"> <context:annotation-config /> <context:component-scan base-package="com.sky.learn" /> <bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor" /> <bean name="hello" class="org.springframework.remoting.caucho.HessianServiceExporter"> <property name="service" ref="helloService" /> <property name="serviceInterface" value="com.sky.learn.inf.HelloService" /> </bean> </beans>3、定义接口与实现类
package com.sky.learn.inf;public interface HelloService {void sayHello(String name);void sayHi(String name);}
package com.sky.learn.impl;import org.springframework.stereotype.Service;import com.sky.learn.inf.HelloService;@Service("helloService")public class HelloServiceImpl implements HelloService {@Overridepublic void sayHello(String name) {// TODO Auto-generated method stubSystem.out.println("Hello World ! Hello " + name + " !");}@Overridepublic void sayHi(String name) {// TODO Auto-generated method stubSystem.out.println("Hi, World ! Hi, " + name + " !");}}4、测试类
package com.sky.learn.test;import com.caucho.hessian.client.HessianProxyFactory;import com.sky.learn.inf.HelloService;public class Test {public static void main(String[] args) {try {String url = "http://localhost:8080/hessian-web/hello";HessianProxyFactory factory = new HessianProxyFactory();HelloService helloService = (HelloService) factory.create(HelloService.class, url);helloService.sayHello("sky");String url2 = "http://localhost:8080/hessian-web/hi";HelloService helloService2 = (HelloService) factory.create(HelloService.class, url2);helloService2.sayHi("sky");} catch (Exception e) {e.printStackTrace();}}}将项目发布,运行测试类控制台输出:
Hello World ! Hello sky !Hi, World ! Hi, sky !
阅读全文
0 0
- Hessian 示例
- Hessian 使用示例总结
- hessian应用示例
- Hessian简单示例
- Hessian简单示例
- hessian简单示例
- Hessian探究(一)Hessian入门示例
- Hessian学习与示例
- Hessian 原理分析、代码示例
- Hessian服务端和客户端示例
- Hessian
- hessian
- Hessian
- Hessian
- hessian
- Hessian
- Hessian
- Hessian
- hihocoder #1539 : 数组重排3
- vue.js学习小结
- 文章标题
- DenseNet的使用
- 五、java中的关键字
- Hessian 示例
- java中的类修饰符、成员变量修饰符、方法修饰符。
- 二分图最大匹配问题之网络流算法
- HTML标签
- 栈、堆、方法区简介
- 初学java,写个期末考试的题
- js关闭当前页面刷新父页面
- 微信分享给朋友圈/朋友/判断网络类型/支付在vue里面亲测
- js学习记录(ajax each() push())