源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

spring boot整合hessian的示例

  • 时间:2020-12-03 08:12 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:spring boot整合hessian的示例
[b]首先添加hessian依赖[/b]
<dependency>  
   <groupId>com.caucho</groupId>  
    <artifactId>hessian</artifactId>  
    <version>4.0.38</version>
</dependency>
[b]服务端:HessianServer,端口号:8090[/b]
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);
  }
//发布服务
  @Bean(name = "/HelloWorldService")
  public HessianServiceExporter accountService() {
    HessianServiceExporter exporter = new HessianServiceExporter();
    exporter.setService(helloWorldService);
    exporter.setServiceInterface(HelloWorldService.class);
    return exporter;
  }
}
[b]客户端代码:HessianClient,同服务端一样引入hessian依赖,端口号:8092[/b]
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.");
  }
}
访问地址即可:[url=http://localhost:8092/test]http://localhost:8092/test[/url] [b]PS:springboot hessian[/b] 注意把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: [url=https://git.oschina.net/wong_loong/rpc.git]https://git.oschina.net/wong_loong/rpc.git[/url] 以上所述是小编给大家介绍的spring boot整合hessian的示例,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对编程素材网网站的支持!
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部