jar包hessian 4.0.38

一、基于servlet的配置

1、需要创建一个接口

package com.yaoxun.spring4.hessian;/*** 测试Hessian服务接口* @author Loren**/
public interface HelloService {/*** 说* @param name*/public void sayHello(String name);}

2、编写实现类

package com.yaoxun.spring4.hessian.impl;import com.yaoxun.spring4.hessian.HelloService;/*** HelloSerivce实现类* @author Loren**/
public class HelloServiceImpl implements HelloService {@Overridepublic void sayHello(String name) {System.out.println("Hello " + name + "!");}}

3、配置web.xml文件

<!-- Hessian配置 --><servlet><servlet-name>hessian-service</servlet-name><servlet-class>com.caucho.hessian.server.HessianServlet</servlet-class><init-param><!-- 服务接口的实现类 --><param-name>home-class</param-name><param-value>com.yaoxun.spring4.hessian.impl.HelloServiceImpl</param-value></init-param><init-param><!-- 服务接口 --><param-name>home-api</param-name><param-value>com.yaoxun.spring4.hessian.HelloService</param-value></init-param></servlet><servlet-mapping><servlet-name>hessian-service</servlet-name><url-pattern>/hessian</url-pattern></servlet-mapping>

4、启动服务器访问

http://localhost:8080/spring4/hessian

出现

Hessian Requires POST

说明配置成功

5、客户端代码

package com.yaoxun.spring4.hessian.test;import java.net.MalformedURLException;import com.caucho.hessian.client.HessianProxyFactory;
import com.yaoxun.spring4.hessian.HelloService;/*** Hessian测试* @author Loren**/
public class HessianTest {public static void main(String[] args) throws MalformedURLException {String url = "http://localhost:8080/spring4/hessian";HessianProxyFactory factory = new HessianProxyFactory();HelloService helloService = (HelloService) factory.create(HelloService.class,url);helloService.sayHello("张三");}}

二、与springMVC进行整合

1、编写接口和实现类,与servlet方式类似

2、配置web.xml文件

 <!-- springmvc的配置 --><servlet><servlet-name>springDispatcherServlet</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><init-param><param-name>contextConfigLocation</param-name><param-value>classpath:spring/springmvc.xml</param-value></init-param><load-on-startup>1</load-on-startup><async-supported>true</async-supported></servlet><servlet-mapping><servlet-name>springDispatcherServlet</servlet-name><url-pattern>/</url-pattern></servlet-mapping><!-- hessian的配置 --><servlet><servlet-name>hessian</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><init-param><param-name>contextConfigLocation</param-name><param-value>classpath:hessian/spring-hessian.xml</param-value></init-param><load-on-startup>1</load-on-startup></servlet><servlet-mapping><servlet-name>hessian</servlet-name><url-pattern>*.h</url-pattern></servlet-mapping>

3、配置springmvc.xml用于springmvc的访问拦截

<?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:mvc="http://www.springframework.org/schema/mvc"xmlns:context="http://www.springframework.org/schema/context"xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsdhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd"><context:component-scan base-package="com.yaoxun.spring4.web.handler"></context:component-scan><bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping"></bean><bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter"></bean><!-- 配置视图解析器 要求将jstl的包加到classpath --><!-- ViewResolver --><beanclass="org.springframework.web.servlet.view.InternalResourceViewResolver"><property name="prefix" value="/WEB-INF/jsp/" /><property name="suffix" value=".jsp" /></bean></beans>

4、配置spring-hessian.xml用于hessian提供服务

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd"><bean id="helloService" class="com.yaoxun.spring4.hessian.impl.HelloServiceImpl"></bean><bean name="/hello.h" class="org.springframework.remoting.caucho.HessianServiceExporter"><property name="service" ref="helloService"></property><property name="serviceInterface" value="com.yaoxun.spring4.hessian.HelloService"></property></bean></beans>

启动服务器,请求

http://localhost:8080/spring4/hello.h

出现:

HTTP Status 405 - HessianServiceExporter only supports POST requests

表示配置成功

-------------------------------------------------------------------------以下代码是他人编写的------------------------------------------------------------------------------------------------

6、客户端代码

hessian-client.xml

<?xml version="1.0" encoding="UTF-8"?>
 2 <beans xmlns="http://www.springframework.org/schema/beans"
 3     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
 4     xsi:schemaLocation="http://www.springframework.org/schema/beans
 5         http://www.springframework.org/schema/beans/spring-beans.xsd
 6         http://www.springframework.org/schema/context
 7         http://www.springframework.org/schema/context/spring-context.xsd">
 8
 9     <bean id="hessianClient"
10         class="org.springframework.remoting.caucho.HessianProxyFactoryBean">
11         <property name="serviceUrl">
12             <value>http://localhost:8080/spring-mvc4-rest/hessian/service</value>
13         </property>
14         <property name="serviceInterface">
15             <value>com.cnblogs.yjmyzz.service.hessian.HelloService</value>
16         </property>
17     </bean>
18
19 </beans>

调用示例

 package com.cnblogs.yjmyzz.test;
 2 import java.net.MalformedURLException;
 3
 4 import org.junit.Test;
 5 import org.springframework.context.ApplicationContext;
 6 import org.springframework.context.support.ClassPathXmlApplicationContext;
 7
 8 import com.cnblogs.yjmyzz.service.hessian.HelloService;
 9
10 public class HessianServiceTest {
11     @SuppressWarnings("resource")
12     @Test
13     public void testService() throws MalformedURLException {
14         ApplicationContext context = new ClassPathXmlApplicationContext(
15                 "hessian-client.xml");
16         HelloService hello = (HelloService) context.getBean("hessianClient");
17         System.out.println(hello.helloWorld("jimmy.yang"));
18     }
19 }

Hessian的入门相关推荐

  1. Hessian 使用入门

    为什么80%的码农都做不了架构师?>>>    本篇主要介绍Hessian的入门知识,包括Hessian服务端的搭建和客户端的调用. 1 服务器搭建   1.1 创建普通Web工程 ...

  2. 远程调用——hessian使用入门

    Hessian是一个轻量级的remoting onhttp工具,使用简单的方法提供了RMI的功能. 相比WebService,Hessian更简单.快捷.采用的是二进制RPC协议,因为采用的是二进制协 ...

  3. Hessian入门(与Spring集成)

    2019独角兽企业重金招聘Python工程师标准>>> Hessian入门(与Spring集成) By:wtang 说明 : 1.    讲述如何配置Hessian的服务器端(与Sp ...

  4. Hessian学习总结(一)——Hessian入门

    一.远程通讯协议的基本原理 网络通信需要做的就是将流从一台计算机传输到另外一台计算机,基于传输协议和网络 IO 来实现,其中传输协议比较出名的有 http . tcp . udp 等等, http . ...

  5. Hessian Binary Web Service Protocol远程接口调用入门

    摘要:Hessian是一个轻量级的remoting onhttp工具,使用简单的方法提供了RMI的功能. 相比WebService,Hessian更简单.快捷.采用的是二进制RPC协议,因为采用的是二 ...

  6. JAVA spring hessian_Spring Boot整合hessian入门

    前言 看了其他的文章发现,大多数都是只写了关键的部分,对于一个初学者来说只能明白用了什么东西,但实际动手发现,项目还存在一些问题,通过本篇文章,可以避免一些问题,节省一些时间成本. Hessian简介 ...

  7. 简单明了,一文入门视觉SLAM

    作者 | 黄浴 转载自知乎 [导读]SLAM是"Simultaneous Localization And Mapping"的缩写,可译为同步定位与建图.最早,SLAM 主要用在机 ...

  8. 化繁为简,一张图看懂梯度、散度、旋度、Jacobian、Hessian和Laplacian

    来源|王赟 Maigo@知乎,https://zhuanlan.zhihu.com/p/35323714 本文仅作学术分享,如有侵权,请联系后台作删文处理. 一.入门 图中的细实线箭头表示了四种一阶微 ...

  9. 免费教材丨第49期:数学基础课程----漫画线性代数、微积分超入门

    小编说 彭亮老师的<深度学习基础>和<深度学习进阶>共计56讲的视频课程已经发放结束了,接下来我们发放什么教材呢? 过去几个月里,有不少人联系我,向我表达他们对人工智能.数据科 ...

最新文章

  1. 1231. The Embarrassed Cryptography
  2. RESTful API介绍
  3. JQuery 总结(7) index() data() each() 选项卡 表单验证
  4. 04-JDBC连接MySQL数据库【修改数据】
  5. C# Linq to SQL — Group by
  6. tabindex, taborder和notab属性的区别
  7. python数据分析实战案例-Python数据分析案例实战
  8. Tomcat 在mac上(Idea)端口冲突解决办法
  9. Confluence 6 管理协同编辑 - 最大编辑者的限制
  10. 夺命雷公狗ThinkPHP项目之----企业网站13之文章列表页的实现(主要是分页的实现)...
  11. MySQL自动化审核平台部署说明
  12. vs error:无法打开源文件“stdafx.h
  13. 关于html 音乐播放器代码|音乐播放器网页代码大全(转),关于HTML 音乐播放器代码|音乐播放器网页代码大全...
  14. 瑞士证交所主席认为发行加密瑞士法郎有益经济发展
  15. 【leetcode】1419. Minimum Number of Frogs Croaking
  16. 字符集详解(一看就懂系列)
  17. 广播计算机应用基础,2019年秋季考试《计算机应用基础》在线考核试题 广播幻灯片操作应选择的功能区是...
  18. [顶会举办地速查] - 深度学习顶会:CVPR、ICCV、ECCV 历年举办地点(2015~2022)
  19. Windows下控制鼠标移动和点击的C语言实现
  20. python保留小数点后位数_Python保留指定位数的小数

热门文章

  1. 711 的成功之道 - 读《零售的哲学》
  2. matlab使用LAN网口TCP/IP通信对大华可编程电源控制
  3. 如何打开vhdx文件
  4. 二分类、多分类和多标签分类
  5. mysql 删除的sql语句怎么写_SQL 删除语句怎么写呢?
  6. 数电实验5 秒表初步
  7. 【图像分割】MGA:Motion Guided Attention for Video Salient Object Detection
  8. java连接sql server数据库的代码如何改成连接mysql_连接sqlserver数据库代码
  9. Apache个人用户主页设置
  10. 【渗透测试】VulnHub-GoldenEye-1