spring Rmi 客户端是通过 RmiProxyFactoryBean 和它的父类来完成 查找远程对象 生成代理对象 方法调用
RmiProxyFactoryBean 定义
public class RmiProxyFactoryBean extends RmiClientInterceptor implements FactoryBean, BeanClassLoaderAware {
}
父类RmiClientInterceptor 定义
public class RmiClientInterceptor extends RemoteInvocationBasedAccessor implements MethodInterceptor {
//spring容器 bean实例化阶段 是否要 查找远程对象 预查找
private boolean lookupStubOnStartup = true;
//查找过的 远程对象是否进行缓存
private boolean cacheStub = true;
//如果连接失败 是否刷新远程调用stub
private boolean refreshStubOnConnectFailure = false;
//rmi客户端 套接字工厂
private RMIClientSocketFactory registryClientSocketFactory;
//缓存远程调用对象
private Remote cachedStub;
//查找远程对象时用到的监控器
private final Object stubMonitor = new Object();
//.....略
}
一:查找远程服务对象
RmiProxyFactoryBean 是InitializingBean接口的实现 Spring容器在bean的实例化(getBean)阶段 回调afterPropertiesSet 来查找远程对象 然后 生成远程代理对象
public void afterPropertiesSet() {
//父类RmiClientInterceptor检查serviceUrl是否配置
//父类RmiClientInterceptor 查找远程对象
super.afterPropertiesSet();
//远程调用接口检查
if (getServiceInterface() == null) {
throw new IllegalArgumentException("Property 'serviceInterface' is required");
}
//创建代理对象
//因