当前位置: 移动技术网 > IT编程>开发语言>Java > spring boot整合hessian的示例

spring boot整合hessian的示例

2019年07月22日  | 移动技术网IT编程  | 我要评论

首先添加hessian依赖

<dependency>  
   <groupid>com.caucho</groupid>  
    <artifactid>hessian</artifactid>  
    <version>4.0.38</version>
</dependency>

服务端:hessianserver,端口号: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);
  }
//发布服务
  @bean(name = "/helloworldservice")
  public hessianserviceexporter accountservice() {
    hessianserviceexporter exporter = new hessianserviceexporter();
    exporter.setservice(helloworldservice);
    exporter.setserviceinterface(helloworldservice.class);
    return exporter;
  }
}

客户端代码:hessianclient,同服务端一样引入hessian依赖,端口号: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.");
  }
}

访问地址即可:

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:

以上所述是小编给大家介绍的spring boot整合hessian的示例,希望对大家有所帮助

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网