摘要:相比,更簡單快捷。采用的是二進制協(xié)議,因為采用的是二進制協(xié)議,所以它很適合于發(fā)送二進制數(shù)據。創(chuàng)建接口創(chuàng)建實現(xiàn)類類端在這個包下服務端包類將服務端的代碼打包安裝到本地倉庫,打開瀏覽器輸入即可。
前言
看了其他的文章發(fā)現(xiàn),大多數(shù)都是只寫了關鍵的部分,對于一個初學者來說只能明白用了什么東西,但實際動手發(fā)現(xiàn),項目還存在一些問題,通過本篇文章,可以避免一些問題,節(jié)省一些時間成本。
Hessian簡介Hessian是一個輕量級的remoting onhttp工具,使用簡單的方法提供了RMI的功能。 相比WebService,Hessian更簡單、快捷。采用的是二進制RPC協(xié)議,因為采用的是二進制協(xié)議,所以它很適合于發(fā)送二進制數(shù)據。
但是它的參數(shù)和返回值都需要實現(xiàn)Serializable接口。
由于Hessian是一個遠程調用的工具,那么我們需要創(chuàng)建2個springboot項目來模擬,服務端項目:springboot-hessian-server,客戶端項目:springboot-hessian-client.
springboot-hessian-server端application.properties
server.port=8081
server端pom.xml
com.caucho hessian 4.0.38 org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-maven-plugin true
需要注意上面那個插件,默認的時候創(chuàng)建,但是沒有下面
創(chuàng)建service接口
public interface HelloWorldService { String sayHello(String name); }
創(chuàng)建service實現(xiàn)類
@Service public class HelloWorldServiceImpl implements HelloWorldService { @Override public String sayHello(String name) { return "Hello world! "+ name; } }
Application類
@SpringBootApplication public class TestSpringbootHessianApplication { public static void main(String[] args) { SpringApplication.run(TestSpringbootHessianApplication.class, args); } @Autowired private HelloWorldService helloWorldService; @Bean(name = "/hello/world/service") public HessianServiceExporter accountService(){ HessianServiceExporter exporter = new HessianServiceExporter(); exporter.setService(helloWorldService); exporter.setServiceInterface(HelloWorldService.class); return exporter; }client端
application.properties
server.port=8082
pom.xml
com.caucho hessian 4.0.38 org.springframework.boot spring-boot-starter-web com.test.springboot.hessian test-hessian 0.0.1-SNAPSHOT
Application類
@SpringBootApplication public class TestSpringbootHessianClientApplication { public static void main(String[] args) { SpringApplication.run(TestSpringbootHessianClientApplication.class, args); } @Bean public HessianProxyFactoryBean helloClient(){ HessianProxyFactoryBean factoryBean = new HessianProxyFactoryBean(); factoryBean.setServiceUrl("http://localhost:8081/hello/world/service"); factoryBean.setServiceInterface(HelloWorldService.class); return factoryBean; } }
controller
@RestController public class HelloWorldController { @Autowired HelloWorldService helloWorldService; @RequestMapping("/test") public String test(){ return helloWorldService.sayHello("zzz"); } }
將服務端的代碼打包安裝到本地倉庫,打開瀏覽器輸入 http://localhost:8082/test 即可。
附上本人的git地址:server端
https://gitee.com/BAKERSTREET...
client端
https://gitee.com/BAKERSTREET...
文章版權歸作者所有,未經允許請勿轉載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉載請注明本文地址:http://m.hztianpu.com/yun/72790.html
摘要:當提供程序線程池耗盡時,不能發(fā)送到使用者端。一些錯誤修正動態(tài)配置不能刪除,支持參數(shù),監(jiān)控統(tǒng)計問題等新功能支持手冊線程池耗盡時自動堆棧轉儲。在注冊表無法連接時被阻止。正常關機,在注冊表取消注冊和線程池關閉之間增加額外的等待時間。 dubbo分析showImg(https://segmentfault.com/img/bVbam2f?w=1726&h=686); dubbo為什么要對接sp...
摘要:最近閑暇時寫了一個小測試的工具,為了方便使用了。該測試工具最關鍵的步驟是動態(tài)加載每個測試模塊對應的的包。這是我考慮到是不是的比較特殊,不是。具體參見此大神的實驗。遂修改代碼請輸入代碼 最近閑暇時寫了一個hessian 小測試的工具,為了方便使用了spring boot。該測試工具最關鍵的步驟是動態(tài)加載每個測試模塊對應的hessian api的jar包。開始的加載代碼為: URLClas...
摘要:前提好幾周沒更新博客了,對不斷支持我博客的童鞋們說聲抱歉了。熟悉我的人都知道我寫博客的時間比較早,而且堅持的時間也比較久,一直到現(xiàn)在也是一直保持著更新狀態(tài)。 showImg(https://segmentfault.com/img/remote/1460000014076586?w=1920&h=1080); 前提 好幾周沒更新博客了,對不斷支持我博客的童鞋們說聲:抱歉了!。自己這段時...
摘要:說明目前互聯(lián)網公司,大部分項目都是基于分布式,一個項目被拆分成幾個小項目,這些小項目會分別部署在不同的計算機上面,這個叫做微服務。當一臺計算機的程序需要調用另一臺計算機代碼的時候,就涉及遠程調用。此時就粉末登場了。 showImg(https://s2.ax1x.com/2019/07/05/ZaELxe.jpg); 說明 目前互聯(lián)網公司,大部分項目都是基于分布式,一個項目被拆分成幾個...
閱讀 1244·2023-04-26 02:46
閱讀 697·2023-04-25 19:38
閱讀 705·2021-10-14 09:42
閱讀 1311·2021-09-08 09:36
閱讀 1423·2019-08-30 15:44
閱讀 1382·2019-08-29 17:23
閱讀 2305·2019-08-29 15:27
閱讀 864·2019-08-29 14:15