spring整合hessian简化rpc调用

maven配置:略

服务端
HessianServiceExporterController.java

/**
 * web.xml中不需要额外的servlet.
 * 对于hessian调用的理解,实际上就是http请求,然后在请求头加了特殊的Header,
 * 请求体的内容使用hessian协议序列化和反序列化。
 * spring提供了HessianServiceExporter,封装了协议处理的部分,
 * 我们只需要注入service和serviceInterface即可。
 * 所以实现将hessian调用简化的逻辑是,
 * 接收/hessian/**请求,根据请求的uri获取对应的HessianServiceExporter。
 * 每一个HessianServiceExporter封装一个service。
 * 将service的name和uri也对应起来(使用了HessianService注解的service),
 * 那么我们只需要提供service,就可以将多个service暴露为hessian服务了。
 *
 */
@Controller
@RequestMapping("/hessian")
public class HessianServiceExporterController {
	private final Logger logger = LoggerFactory.getLogger(this.getClass());
	private Map<String, HessianServiceExporter> uri2Exporter = new HashMap<>();
	private Map<String, Object> beanName2Service;

	@PostConstruct
	public void init() throws ClassNotFoundException {
		ApplicationContext appContext = AppContextHolder.getApplicationContext();
		WebApplicationContext webappContext = AppContextHolder.getWebApplicationContext();
		beanName2Service = appContext.getBeansWithAnnotation(HessianService.class);
		beanName2Service.putAll(webappContext.getBeansWithAnnotation(HessianService.class));
		logger.info("beanName2Service:"+beanName2Service.toString());
		String contextPath = webappContext.getServletContext().getContextPath();
		for (String beanname : beanName2Service.keySet()) {
			Object service = beanName2Service.get(beanname);
			Class<?> serviceInterface = findServiceInterface(service);
			HessianServiceExporter exporter = new
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值