首先添加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的示例,希望对大家有所帮助
如对本文有疑问, 点击进行留言回复!!
before社区电量是什么意思 Before社区电量获得方法
RecycleView入门详解(教你全面掌握RecycleView用法)
动态权限请求框架RxPermissions(几行代码搞定权限)
URL路径@PathVariable出现点号“.“时值遭截断问题
网友评论