Hessian学习(springboot环境)
Hessian介绍:
Hessian是一个轻量级的remoting onhttp工具,使用简单的方法提供了RMI的功能。 相比WebService,Hessian更简单、快捷。采用的是二进制RPC协议,因为采用的是二进制协议,所以它很适合于发送二进制数据。
Hessian分为服务端和客户端两部分。
1、添加pom.xml依赖
<dependency>
<groupId>com.caucho</groupId>
<artifactId>hessian</artifactId>
<version>4.0.37</version>
</dependency>
2、添加interface 接口
package com.sxdx.oa_service.hessian.service;
public interface HelloWorldService {
String sayHello(String name);
}
3、实现HelloWorldService 这个接口
package com.sxdx.oa_service.hessian.service.impl; import com.sxdx.oa_service.hessian.service.HelloWorldService;
import org.springframework.stereotype.Service; @Service
public class HelloWorldServiceImpl implements HelloWorldService {
@Override
public String sayHello(String name) {
return "Hello World! " + name;
}
}
4、发布服务
package com.sxdx.oa_service.hessian.controller; import com.sxdx.oa_service.hessian.service.HelloWorldService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.remoting.caucho.HessianServiceExporter;
import org.springframework.stereotype.Controller; @Controller
public class HessianController { @Autowired
private HelloWorldService helloWorldService; //发布服务 (此处定义外部访问路径,比如本例中,对外提供的API 为 http://127.0.0.1:8080/oaframe/HelloWorldService)
@Bean(name = "/HelloWorldService")
public HessianServiceExporter accountService() {
HessianServiceExporter exporter = new HessianServiceExporter();
exporter.setService(helloWorldService);
exporter.setServiceInterface(HelloWorldService.class);
return exporter;
}
}
二、客户端
1、添加pom.xml依赖
<dependency>
<groupId>com.caucho</groupId>
<artifactId>hessian</artifactId>
<version>4.0.37</version>
</dependency>
2、添加interface 接口(需要和服务端接口类的类名、方法名完全一样,对包路径是否相同没有要求)
package cn.org.csip.vim.sso.service;
public interface HelloWorldService {
String sayHello(String name);
}
3、添加Hessian客户端组件(我本来把这部分代码写在了一个Controller中,但是启动会报错,放在启动类中就可以,暂时没确定原因,感觉像是spring注册bean顺序的原因)
package cn.org.csip.vim.sso; import cn.org.csip.vim.sso.service.HelloWorldService;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.remoting.caucho.HessianProxyFactoryBean; @SpringBootApplication
public class HessiantestApplication {
@Bean
public HessianProxyFactoryBean helloClient() {
HessianProxyFactoryBean factory = new HessianProxyFactoryBean();
factory.setServiceUrl("http://127.0.0.1:8080/oaframe/HelloWorldService");
factory.setServiceInterface(HelloWorldService.class);
return factory;
}
public static void main(String[] args) {
SpringApplication.run(HessiantestApplication.class, args);
}
}
4、添加访问测试代码
package cn.org.csip.vim.sso.controller; import cn.org.csip.vim.sso.service.HelloWorldService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; @RestController
public class HessianController {
@Autowired
private HelloWorldService helloWorldService; @RequestMapping("/test")
public String test() {
return helloWorldService.sayHello("Spring boot with Hessian.");
} }
5、浏览器访问测试(返回成功)

参考文章:https://blog.csdn.net/sias1991/article/details/75270547
Hessian学习(springboot环境)的更多相关文章
- Jenkins持续集成学习-Windows环境进行.Net开发4
目录 Jenkins持续集成学习-Windows环境进行.Net开发4 目录 前言 目标 Github持续集成 提交代码到Github 从Github更新代码 git上显示构建状态 自动触发构建 Gi ...
- 学习SpringBoot,整合全网各种优秀资源,SpringBoot基础,中间件,优质项目,博客资源等,仅供个人学习SpringBoot使用
学习SpringBoot,整合全网各种优秀资源,SpringBoot基础,中间件,优质项目,博客资源等,仅供个人学习SpringBoot使用 一.SpringBoot系列教程 二.SpringBoot ...
- 深度学习主机环境配置: Ubuntu16.04 + GeForce GTX 1070 + CUDA8.0 + cuDNN5.1 + TensorFlow
深度学习主机环境配置: Ubuntu16.04 + GeForce GTX 1070 + CUDA8.0 + cuDNN5.1 + TensorFlow 最近在公司做深度学习相关的学习和实验,原来一直 ...
- react native 学习一(环境搭配和常见错误的解决)
react native 学习一(环境搭配) 首页,按照http://reactnative.cn/docs/0.30/getting-started.html#content上的介绍,下载安装pyt ...
- emberjs学习一(环境和第一个例子)
code { margin: 0; padding: 0; white-space: pre; border: none; background: transparent; } code, pre t ...
- 1 python学习——python环境配置
1 python学习--python环境配置 要学习python语言,光看书看教程还是不好,得动手去写.当然,不管学习什么编程语言,最佳的方式还在于实践. 要实践,先得有一个Python解释器来解释执 ...
- (转)深度学习主机环境配置: Ubuntu16.04+Nvidia GTX 1080+CUDA8.0
深度学习主机环境配置: Ubuntu16.04+Nvidia GTX 1080+CUDA8.0 发表于2016年07月15号由52nlp 接上文<深度学习主机攒机小记>,这台GTX10 ...
- 深度学习开发环境搭建教程(Mac篇)
本文将指导你如何在自己的Mac上部署Theano + Keras的深度学习开发环境. 如果你的Mac不自带NVIDIA的独立显卡(例如15寸以下或者17年新款的Macbook.具体可以在"关 ...
- supervessel-免费云镜像︱GPU加速的Caffe深度学习开发环境
开发环境介绍 在SuperVessel云上,我们为大家免费提供当前火热的caffe深度学习开发环境.SuperVessel的Caffe有如下优点: 1) 免去了繁琐的Caffe环境的安装配置,即申请即 ...
- Shell学习之环境变量配置文件(三)
Shell学习之环境变量配置文件 目录 环境变量配置文件简介 环境变量配置文件作用 其他配置文件和登录信息 环境变量配置文件简介 环境变量配置文件简介 环境变量配置文件中主要是定义对系统操作环境生效的 ...
随机推荐
- shell文件测试,菜单表示思想
---恢复内容开始--- 文件测试表达式 -f 文件存在且为普通文件 -d 文件存在且为目录文件 -s 文件大小不为0则真 -e 文件存在则真 -r 文件存且可 ...
- Activity中满屏和去标题的实现方法
两种方式: 在xml文件中进行配置 在项目的清单文件AndroidManifest.xml中,找到需要全屏或设置成无标题栏的Activity,在该Activity进行如下配置即可. 实现全屏效果: a ...
- nexus的安装和简介(2)
上传jar包到私服 1. 配置settings.xml 需要在客户端即部署dao工程的电脑上配置 maven环境,并修改 settings.xml 文件,配置连接私服的用户和密码 . 此用户名和密码用 ...
- Linux ssh命令
SSH(远程连接工具)连接原理:ssh服务是一个守护进程(demon),系统后台监听客户端的连接,ssh服务端的进程名为sshd,负责实时监听客户端的请求(IP 22端口),包括公共秘钥等交换等信息. ...
- EOS keosd
[EOS keosd] The program keosd, located in the eos/build/programs/keosd folder within the EOSIO/eos r ...
- 第一章 C++语言入门
标准数据类型 C++语言提供了丰富的数据类型,如整数类型.实数类型(浮点数).字符类型等.每种数据类型均有均值范围,Dev-C++(4.9.9.2)是Windows平台 ...
- React Context(一):隐式传递数据
一 Context概述 Context provides a way to pass data through the component tree without having to pass pr ...
- [leetcode]45. Jump Game II青蛙跳(跳到终点最小步数)
Given an array of non-negative integers, you are initially positioned at the first index of the arra ...
- flex布局实现elment容器布局
一.flex布局是什么 flex布局,意为"弹性布局",是一种响应式的布局方法 采用 Flex 布局的元素,称为 Flex 容器,它的所有子元素自动成为容器成员. 先放上一个ele ...
- thinkphp用ajax遇到的坑——ajax请求没有反应
view视图的 html 的 js 代码如下, $.ajax({ url:"test",//这里指向的就不再是页面了,而是一个方法. ...