spring boot整合hessian的示例

网友投稿 367 2023-04-27


spring boot整合hessian的示例

首先添加hessian依赖

com.caucho

hessian

4.0.38

服务端: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的问题。

hessian

4.0.37

git:

https://git.oschina.net/wong_loong/rpc.git

以上所述是给大家介绍的spring boot整合hessian的示例,希望对大家有所帮助,如果大家有任何疑问请给我留言,会及时回复大家的。在此也非常感谢大家对我们网站的支持!


版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:vue深入解析之render function code详解
下一篇:mock数据生成工具(mock数据怎么造)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~