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