spring boot整合hessian的示例
2017-07-18 09:27
519 查看
首先添加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."); } }
访问地址即可:http://localhost:8092/test
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:
https://git.oschina.net/wong_loong/rpc.git
以上所述是小编给大家介绍的spring boot整合hessian的示例,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对脚本之家网站的支持!
您可能感兴趣的文章:
相关文章推荐
- spring boot整合mybatis+mybatis-plus的示例代码
- Spring boot 整合CXF开发web service(单独)
- springMVC和Shiro框架整合使用简单示例 【转】
- Spring Boot教程(三十五)整合elk(2)
- Flex+BlazeDS整合J2ee示例
- Spring Boot 基础篇之 整合Mybatis 实现 RESTful API
- SpringBoot整合jersey的示例代码
- spring boot 添加数据源 整合 mybaties (三)
- kafka+storm整合 java示例
- spring boot 整合quartz,并实现quartz的job实现自动注入功能
- Spring整合Struts2简单示例
- Spring boot整合mongodb
- 简单示例:Spring4 整合 单个Redis服务
- Spring Boot学习(九)之Spring Boot整合MyBatis
- Struts2SpringHibernate整合示例,一个HelloWorld版的在线书店(项目源码+详尽注释+单元测试)
- Spring Boot整合使用JdbcTemplate
- MyBatis-Spring整合示例
- spring boot 整合 spring security 之使用数据库验证
- Struts1.2+Spring1.2+HIbernate3.1整合示例代码详解(一)
- [Java] SSH框架笔记_框架整合示例(一)