spring boot整合hessian的示例
首先添加hessian依赖
com.caucho hessian 4.0.38 
服务端:HessianServer,端口号:8090
publicinterfaceHelloWorldService{
StringsayHello(Stringname);
}
@Service("HelloWorldService")
publicclassHelloWorldServiceImplimplementsHelloWorldService{
@Override
publicStringsayHello(Stringname){
return"HelloWorld!"+name;
}
}
@SpringBootApplication
publicclassHessianServerApplication{
@Autowired
privateHelloWorldServicehelloWorldService;
publicstaticvoidmain(String[]args){
SpringApplication.run(HessianServerApplication.class,args);
}
//发布服务
@Bean(name="/HelloWorldService")
publicHessianServiceExporteraccountService(){
HessianServiceExporterexporter=newHessianServiceExporter();
exporter.setService(helloWorldService);
exporter.setServiceInterface(HelloWorldService.class);
returnexporter;
}
}
客户端代码:HessianClient,同服务端一样引入hessian依赖,端口号:8092
publicinterfaceHelloWorldService{
StringsayHello(Stringname);
}
@SpringBootApplication
publicclassHessianClientApplication{
@Bean
publicHessianProxyFactoryBeanhelloClient(){
HessianProxyFactoryBeanfactory=newHessianProxyFactoryBean();
factory.setServiceUrl("http://localhost:8090/HelloWorldService");
factory.setServiceInterface(HelloWorldService.class);
returnfactory;
}
publicstaticvoidmain(String[]args){
SpringApplication.run(HessianClientApplication.class,args);
}
}
@RestController
publicclassTestController{
@Autowired
privateHelloWorldServicehelloWorldService;
@RequestMapping("/test")
publicStringtest(){
returnhelloWorldService.sayHello("SpringbootwithHessian.");
}
}
访问地址即可:http://localhost:8092/test
PS:springboothessian
注意把hessian的依赖换成4.0.38或者把git文件里的4.0.37放到maven私服中去,推荐使用4.0.37版本。38版本存在序列化bigdecimal的问题。
com.caucho hessian 4.0.37 
git:
https://git.oschina.net/wong_loong/rpc.git
以上所述是小编给大家介绍的springboot整合hessian的示例,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对毛票票网站的支持!
声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:czq8825#qq.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。
