springboot整合hessian

1.新建兩個springboot項目 HessianServer和HessianClient

2.添加hessian maven引用

<dependency>    
      <groupId>com.caucho</groupId>    
       <artifactId>hessian</artifactId>    
        <version>4.0.38</version>
</dependency>

3.HessianServer中添加服務(wù)并實現(xiàn)服務(wù)

HelloWorldService

public interface HelloWorldService {    
    String sayHello(String name);
}

HelloWorldServiceImpl

public class HelloWorldServiceImpl implements HelloWorldService {
    @Override    
    public String sayHello(String name) {
        return "Hello World! " + name;    
    }
}

4.發(fā)布服務(wù),在application中添加

@Autowired
private HelloWorldService helloWorldService;
@Bean(name = "/HelloWorldService")
public HessianServiceExporter accountService() {   
    HessianServiceExporter exporter = new HessianServiceExporter();      
    exporter.setService(helloWorldService);   
    exporter.setServiceInterface(HelloWorldService.class);   
    return exporter;
}

5. HessianClient添加HelloWorldService接口

6.注解配置遠程接口信息

@Bean
public HessianProxyFactoryBean helloClient() {              
      HessianProxyFactoryBean factory = new HessianProxyFactoryBean();   
      factory.setServiceUrl("http://localhost:8090/HelloWorldService");   
      factory.setServiceInterface(HelloWorldService.class);   
      return factory;
}

7.調(diào)用測試

@Autowired
HelloWorldService helloWorldService;
@RequestMapping("/test")
public String test(){
    return helloWorldService.sayHello("Spring boot with Hessian.");
}

8.測試結(jié)果,如下顯示成功

屏幕快照 2016-11-24 下午5.22.20.png

demo地址: https://github.com/HuangPugang/spring-boot-hessian-demo/tree/master

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容