spring boot整合hessian的示例
首先添加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的示例,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对脚本之家网站的支持!
相关文章
SpringCloud之Config配置中心与Redis分布式锁详解
这篇文章主要给大家介绍了SpringCloud Alibaba中Config配置中心,Redis分布式锁,文中有详细的代码示例供大家参考,需要的朋友可以参考阅读2023-05-05
Spring Cloud Config分布式配置中心使用介绍详解
分布式配置中心应用场景 往往,我们使用配置文件管理⼀些配置信息,比如application.yml 单体应用架构:配置信息的管理、维护并不会显得特别麻烦,手动操作就可以,因为就一个工程2022-09-09
详解SpringMVC和MyBatis框架开发环境搭建和简单实用
这篇文章主要介绍了详解SpringMVC和MyBatis框架开发环境搭建和简单实用,具有一定的参考价值,感兴趣的小伙伴们可以参考一下2017-05-05
SpringBoot项目报错:"Error starting ApplicationContext....
这篇文章主要给大家介绍了关于SpringBoot项目报错:“Error starting ApplicationContext. To display the conditions report re-run ...”的解决办法,文中通过图文介绍的非常详细,需要的朋友可以参考下2022-08-08
Java class文件格式之常量池_动力节点Java学院整理
这篇文章主要为大家详细介绍了Java class文件格式之常量池的相关资料,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下2017-06-06


最新评论