1. 架构

细化结构:

1. 1.hessian-study的pom文件

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com.fracong</groupId><artifactId>hessian-study</artifactId><version>0.0.1-SNAPSHOT</version><packaging>pom</packaging><properties><java.version>1.8</java.version><ch.qos.logback.version>1.2.3</ch.qos.logback.version><fastjson-version>1.2.29</fastjson-version></properties><dependencyManagement><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-dependencies</artifactId><version>2.1.2.RELEASE</version><type>pom</type><scope>import</scope></dependency><dependency><groupId>ch.qos.logback</groupId><artifactId>logback-classic</artifactId><version>${ch.qos.logback.version}</version></dependency><dependency><groupId>ch.qos.logback</groupId><artifactId>logback-core</artifactId><version>${ch.qos.logback.version}</version></dependency><!-- json --><dependency><groupId>com.alibaba</groupId><artifactId>fastjson</artifactId><version>${fastjson-version}</version></dependency><!-- commons-lang --><dependency><groupId>org.apache.commons</groupId><artifactId>commons-lang3</artifactId><version>3.0</version></dependency></dependencyManagement><dependencies><dependency><groupId>com.alibaba</groupId><artifactId>fastjson</artifactId></dependency><dependency><groupId>javax.servlet</groupId><artifactId>javax.servlet-api</artifactId><scope>provided</scope></dependency></dependencies><repositories><repository><id>spring-milestones</id><name>Spring Milestones</name><url>https://repo.spring.io/milestone</url></repository></repositories><modules><module>hessian-server</module><module>hessian-client</module><module>hessian-interface</module></modules>
</project>

1.2.hessian-interface的pom文件

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>com.fracong</groupId><artifactId>hessian-study</artifactId><version>0.0.1-SNAPSHOT</version></parent><artifactId>hessian-interface</artifactId>
</project>
1.3.hessian-service的pom文件
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>com.fracong</groupId><artifactId>hessian-study</artifactId><version>0.0.1-SNAPSHOT</version></parent><artifactId>hessian-server</artifactId><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>com.alibaba</groupId><artifactId>fastjson</artifactId></dependency><dependency>    <groupId>com.caucho</groupId>    <artifactId>hessian</artifactId> <version>4.0.38</version>   </dependency><dependency><groupId>${project.parent.groupId}</groupId><artifactId>hessian-interface</artifactId><version>${project.parent.version}</version><type>jar</type></dependency></dependencies>
</project>

1.4.hessian-client的pom文件

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>com.fracong</groupId><artifactId>hessian-study</artifactId><version>0.0.1-SNAPSHOT</version></parent><artifactId>hessian-client</artifactId><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>com.alibaba</groupId><artifactId>fastjson</artifactId></dependency><dependency>    <groupId>com.caucho</groupId>    <artifactId>hessian</artifactId><version>4.0.38</version></dependency><dependency><groupId>${project.parent.groupId}</groupId><artifactId>hessian-interface</artifactId><version>${project.parent.version}</version><type>jar</type></dependency></dependencies>
</project>

2.1.hessian-service的配置文件

server.servlet.context-path=/hessian-server
server.port=8280

2.2.hessian-client的配置文件

server.servlet.context-path=/hessian-client
server.port=8180

3.代码实现
3.1.hessian-interface的统一接口

package com.fracong.hessian.test.myinterface;
public interface HessianTestServiceInterface {public String sayTest(String str);
}

3.2.hessian-service的服务注册
3.2.1.注入service,实现hessian-interface中的接口

package com.fracong.hessian.test.service;
​
import org.springframework.stereotype.Service;
​
import com.fracong.hessian.test.myinterface.HessianTestServiceInterface;
​
@Service
public class HessianTestService implements HessianTestServiceInterface{@Overridepublic String sayTest(String str) {return "aaa-"+str;}
}

3.2.2.注入service的服务发现

书写TestServiceComponent
package com.fracong.hessian.component;
​
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.remoting.caucho.HessianServiceExporter;
import org.springframework.stereotype.Component;
​
import com.fracong.hessian.test.myinterface.HessianTestServiceInterface;
import com.fracong.hessian.test.service.HessianTestService;
​
@Component
public class TestServiceComponent {@Autowiredprivate HessianTestService hessianTestService;@Bean(name = "/HessianTestService")public HessianServiceExporter accountService() {HessianServiceExporter exporter = new HessianServiceExporter();exporter.setService(hessianTestService);exporter.setServiceInterface(HessianTestServiceInterface.class);return exporter;}
}


3.3.hessian-client的客户端发现服务
3.3.1.发现服务

package com.fracong.hessian.test.component;
​
import org.springframework.context.annotation.Bean;
import org.springframework.remoting.caucho.HessianProxyFactoryBean;
import org.springframework.stereotype.Component;
​
import com.fracong.hessian.test.myinterface.HessianTestServiceInterface;
​
@Component
public class HessianClientComponent {@Beanpublic HessianProxyFactoryBean helloClient() {HessianProxyFactoryBean factory = new HessianProxyFactoryBean();//该接口的路径,需要和3.2.2中注册的bean名称一致factory.setServiceUrl("http://localhost:8280/hessian-server/HessianTestService");factory.setServiceInterface(HessianTestServiceInterface.class);return factory;}
}


3.3.2.服务调用测试

package com.fracong.hessian.test.controller;
​
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
​
import com.fracong.hessian.test.myinterface.HessianTestServiceInterface;
​
@RestController
public class TestController {@Autowiredprivate HessianTestServiceInterface hessianService;@RequestMapping(value="/test/{id}")public String test(@PathVariable("id")String id) {String sayTest = hessianService.sayTest("aa"+id);return sayTest;}
}


4.服务启动
4.1.服务端启动

package com.fracong.hessian;
​
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
​
@SpringBootApplication
@ComponentScan("com.fracong")
public class HessianServiceApplication {//启动类入口public static void main(String[] args) {SpringApplication.run(HessianServiceApplication.class,args);    }
}


4.2.客户端启动

package com.fracong.hessian;
​
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
​
@SpringBootApplication
@ComponentScan("com.fracong")
public class HessianClientApplication {public static void main(String[] args) {SpringApplication.run(HessianClientApplication.class, args);}
}


5.测试

http://localhost:8180/hessian-client/test/222
结果:aaa-aa222

springboot结合hessian的使用相关推荐

  1. SpringBoot整合Hessian

    SpringBoot整合Hessian Hessian是一个轻量级的Binary RPC(二进制远程调用协议)协议的remoting on http框架(远程调用框架),这个跟我们以前常用的webse ...

  2. java其他框架杂记

    工作流框架 activiti与flowable的区别 - 分享牛 - CSDN博客 字节码 JVM Class字节码之三-使用BCEL改变类属性 - GarfieldEr007的专栏 - CSDN博客 ...

  3. 项目如何用jetty运行_阿里大牛教你如何用Dubbox+SpringBoot+Docker架构,实现双11项目...

    前言 本篇围绕秒杀抢购应用场景,对当下流行的Dubbox+ Spring Boot+Docker微服务架构解决方案进行讲解.主要内容包括微服务架构介绍.Dubbox 原理及运用.使用Spring Bo ...

  4. SpringBoot基础重难点

    来源:SpringBoot基础重难点 - liangxiaolong - 博客园 1.SpringBoot 1.1 概念 Spring Boot是构建所有基于Spring的应用程序的起点.Spring ...

  5. 爱了!蚂蚁开源的“SpringBoot”框架,新增了这6项功能...

    SOFABoot 是蚂蚁金服开源的基于 Spring Boot 的研发框架,它在 Spring Boot 的基础上,提供了诸如 Readiness Check,类隔离,日志空间隔离等等能力.在增强了 ...

  6. JAVA spring hessian_Springboot写的Hessian例子

    SpringBoot中添加Hessian框架 Hessian一般用来做RPC接口,通过http传输二进制文件,用于程序和程序之间的通信. 在这个例子中,有两个项目,客户端(hessianClient) ...

  7. SpringBoot集成Hasor-Dataway数据查询接口

    目录 一.前言 1.Hasor Core Core 容器框架 设计思想 特性 2.Hasor Web Web 框架 3.Hasor DB JDBC 框架 特性 4.Hasor DataQL DataQ ...

  8. 【Other】最近在研究的, Java/Springboot/RPC/JPA等

    我的Springboot框架,欢迎关注: https://github.com/junneyang/common-web-starter Dubbo-大波-服务化框架 dubbo_百度搜索Dubbo与 ...

  9. dubbo教程总结(springboot+dubbo)

    概述 Apache Dubbo 是一款微服务开发框架,它提供了 RPC通信 与 微服务治理 两大关键能力.这意味着,使用 Dubbo 开发的微服务,将具备相互之间的远程发现与通信能力, 同时利用 Du ...

最新文章

  1. C++_类和动态内存分配2-改进后的String类
  2. 11家车企联手高通、大唐,加速V2X在华商用部署
  3. golang中的方法
  4. [解决]Win7+Tomcat5.5 只能通过localhost或计算机名访问
  5. windows2003 DNS服务器配置
  6. 微软将在新西兰建设其第一个数据中心区域
  7. python列表添加元素到中间_python在列表的元素中间插入空行
  8. (王道408考研数据结构)第七章查找-第二节3:分块查找
  9. 最便宜的鸿蒙手机,今年不再推出鸿蒙手机,却让老旗舰占据优势,降价后变真香...
  10. android+动画+锯齿,Android_rotate--animation 动画旋转两图片,消除动画锯齿现象 android 开发:动画旋转两图片 - 下载 - 搜珍网...
  11. 二叉树的BFS及DFS
  12. mysql 性能统计_MySql 的统计查询性能问题
  13. Bailian3468 电池的寿命【贪心】
  14. 秋招准备之——计算机操作系统
  15. 本地远程连接服务器调试
  16. openGL细分着色器详解
  17. java做微信支付notify_url异步通知服务端的写法
  18. python 3 12306余票查询脚本
  19. android 耳机数据传输,智能手机耳机电路工作原理
  20. java流意外结束_SyntaxError:输入节点js的意外结束

热门文章

  1. 服务器隔一段时间就崩溃,可能是被攻击了
  2. linux env命令用法,Linux env命令
  3. #!/usr/bin/env与#!/usr/bin/
  4. 日本早稻田大学的研究人员,使用AI给黑白照片着色
  5. 日文符号“・”插入sql-server2005乱码问题
  6. 小米android系统没更新,MIUI 10更新小米惹怒老用户 只升UI不升安卓系统版本
  7. 联盟服务器维护到多久,英雄联盟停服多长时间?lol停服维护公告说明[多图]
  8. 财报里的百度智能云,讲出了产业智能化的故事
  9. java js 截取字符串_JavaScript:在JS中截取字符串的方法
  10. gd32F103C8T6 flash填坑