欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

spring boot整合hessian的示例

程序员文章站 2023-12-02 08:45:28
首先添加hessian依赖 com.caucho...

首先添加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的示例,希望对大家有所帮助