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的示例,希望对大家有所帮助
推荐阅读
-
使用Spring Boot集成FastDFS的示例代码
-
spring security4 添加验证码的示例代码
-
Spring整合Quartz分布式调度的示例代码
-
Spring Boot与Spark、Cassandra系统集成开发示例
-
详解spring boot jpa整合QueryDSL来简化复杂操作
-
spring boot aop 记录方法执行时间代码示例
-
spring boot整合Cucumber(BDD)的方法
-
详解Spring Boot下Druid连接池的使用配置分析
-
Spring boot redis cache的key的使用方法
-
Spring Boot利用@Async异步调用:ThreadPoolTaskScheduler线程池的优雅关闭详解