spring boot整合hessian的示例
首先添加hessian依賴
<dependency>
<groupId>com.caucho</groupId>
<artifactId>hessian</artifactId>
<version>4.0.38</version>
</dependency>
服務(wù)端:HessianServer,端口號(hào):8090
public interface HelloWorldService {
String sayHello(String name);
}
@Service("HelloWorldService")
public class HelloWorldServiceImpl implements HelloWorldService {
@Override
public String sayHello(String name) {
return "Hello World! " + name;
}
}
@SpringBootApplication
public class HessianServerApplication {
@Autowired
private HelloWorldService helloWorldService;
public static void main(String[] args) {
SpringApplication.run(HessianServerApplication.class, args);
}
//發(fā)布服務(wù)
@Bean(name = "/HelloWorldService")
public HessianServiceExporter accountService() {
HessianServiceExporter exporter = new HessianServiceExporter();
exporter.setService(helloWorldService);
exporter.setServiceInterface(HelloWorldService.class);
return exporter;
}
}
客戶端代碼:HessianClient,同服務(wù)端一樣引入hessian依賴,端口號(hào):8092
public interface HelloWorldService {
String sayHello(String name);
}
@SpringBootApplication
public class HessianClientApplication {
@Bean
public HessianProxyFactoryBean helloClient() {
HessianProxyFactoryBean factory = new HessianProxyFactoryBean();
factory.setServiceUrl("http://localhost:8090/HelloWorldService");
factory.setServiceInterface(HelloWorldService.class);
return factory;
}
public static void main(String[] args) {
SpringApplication.run(HessianClientApplication.class, args);
}
}
@RestController
public class TestController {
@Autowired
private HelloWorldService helloWorldService;
@RequestMapping("/test")
public String test() {
return helloWorldService.sayHello("Spring boot with Hessian.");
}
}
訪問(wèn)地址即可:http://localhost:8092/test
PS:springboot hessian
注意把hessian的依賴換成4.0.38或者把git文件里的4.0.37放到maven私服中去,推薦使用4.0.37版本。38版本存在序列化bigdecimal的問(wèn)題。
<dependency>
<groupId>com.caucho</groupId>
<artifactId>hessian</artifactId>
<version>4.0.37</version>
</dependency>
git:
https://git.oschina.net/wong_loong/rpc.git
以上所述是小編給大家介紹的spring boot整合hessian的示例,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
相關(guān)文章
完美解決Java獲取文件路徑出現(xiàn)亂碼的問(wèn)題
今天小編就為大家分享一篇完美解決Java獲取文件路徑出現(xiàn)亂碼的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-07-07
SpringBoot YAML語(yǔ)法基礎(chǔ)詳細(xì)整理
YAML 是 “YAML Ain’t Markup Language”(YAML 不是一種標(biāo)記語(yǔ)言)的遞歸縮寫。在開(kāi)發(fā)的這種語(yǔ)言時(shí),YAML 的意思其實(shí)是:“Yet Another Markup Language”(仍是一種標(biāo)記語(yǔ)言),本文給大家介紹的非常詳細(xì),需要的朋友可以參考下2022-10-10
利用Java實(shí)現(xiàn)網(wǎng)站聚合工具
互聯(lián)網(wǎng)上有數(shù)以萬(wàn)億計(jì)的網(wǎng)站,每個(gè)網(wǎng)站大都具有一定的功能。搜索引擎雖然對(duì)互聯(lián)網(wǎng)上的部分網(wǎng)站建立了索引,但是其作為一個(gè)大而全的搜索系統(tǒng),無(wú)法很好的定位到一些特殊的需求。因此本文將介紹一個(gè)用java實(shí)現(xiàn)的網(wǎng)站數(shù)據(jù)聚合工具,需要的可以參考一下2022-01-01
Java中.divide()方法使用及注意事項(xiàng)詳解
divide方法就是bigdecimal類中的一個(gè)除法計(jì)算方法,由于該divide方法參數(shù)類型眾多并且不易理解容易出現(xiàn)錯(cuò)誤,這篇文章主要給大家介紹了關(guān)于Java中.divide()方法使用及注意事項(xiàng)的相關(guān)資料,需要的朋友可以參考下2024-03-03
SpringBoot實(shí)現(xiàn)國(guó)密SM4加密解密的使用示例
在商用密碼體系中,SM4主要用于數(shù)據(jù)加密,本文就來(lái)介紹一下SpringBoot實(shí)現(xiàn)國(guó)密SM4加密解密的使用示例,具有一定的參考價(jià)值,感興趣的可以了解一下2023-10-10
Java如何實(shí)現(xiàn)遠(yuǎn)程文件下載到本地目錄
本文介紹了如何使用Java來(lái)實(shí)現(xiàn)遠(yuǎn)程文件的下載功能,主要通過(guò)HTTPS路徑下載文件到本地目錄,詳細(xì)介紹了相關(guān)代碼和測(cè)試步驟,并提供了實(shí)際案例供參考,本文旨在幫助需要實(shí)現(xiàn)文件下載功能的開(kāi)發(fā)者快速掌握核心技術(shù)2024-10-10

