springboot整合hessian
2016-11-24 本文已影响1204人
黄浦
1.新建两个springboot项目 HessianServer和HessianClient
2.添加hessian maven引用
<dependency>
<groupId>com.caucho</groupId>
<artifactId>hessian</artifactId>
<version>4.0.38</version>
</dependency>
3.HessianServer中添加服务并实现服务
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.发布服务,在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.调用测试
@Autowired
HelloWorldService helloWorldService;
@RequestMapping("/test")
public String test(){
return helloWorldService.sayHello("Spring boot with Hessian.");
}
8.测试结果,如下显示成功
屏幕快照 2016-11-24 下午5.22.20.pngdemo地址: https://github.com/HuangPugang/spring-boot-hessian-demo/tree/master