springboot整合hessian

1.新建两个springboot项目 HessianServer和HessianClient

2.添加hessian maven引用

    
      com.caucho    
       hessian    
        4.0.38


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.测试结果,如下显示成功

springboot整合hessian_第1张图片
屏幕快照 2016-11-24 下午5.22.20.png

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

你可能感兴趣的:(springboot整合hessian)