1. 实际上hessian发布服务是根据接口来发布的,但是接口必须要有对应的实例对象才可以完成服务的暴露
2. hessian在和spring集成的时候,spring做了过多的检查校验
比如: org.springframework.remoting.support.RemoteExporter (spring-context-3.1.1.RELEASE.jar)
protected void checkServiceInterface() throws IllegalArgumentException { Class serviceInterface = getServiceInterface(); Object service = getService(); if (serviceInterface == null) { throw new IllegalArgumentException("Property 'serviceInterface' is required"); } if (service instanceof String) { throw new IllegalArgumentException("Service [" + service + "] is a String " + "rather than an actual service reference: Have you accidentally specified " + "the service bean name as value instead of as reference?"); } /** //以下部分是严格校验,服务对象必须是接口的实例,导致无法将代理对象绑定的接口上发布服务。 if (!serviceInterface.isInstance(service)) { throw new IllegalArgumentException("Service interface [" + serviceInterface.getName() + "] needs to be implemented by service [" + service + "] of class [" + service.getClass().getName() + "]"); }*/ }
上面解释和代码是我注释掉的,去掉检查校验,就可以完成接口+代理对象来完成服务的发布。
具体代码见附件: RemoteExporter.java