您好,登錄后才能下訂單哦!
首先添加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."); } }
訪問地址即可:http://localhost:8092/test
PS:springboot hessian
注意把hessian的依賴換成4.0.38或者把git文件里的4.0.37放到maven私服中去,推薦使用4.0.37版本。38版本存在序列化bigdecimal的問題。
<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ì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)億速云網(wǎng)站的支持!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。