注:SpringFramework版本是3.2.8
1.HttpInvokerServiceExporter
时序图(描述的是serviceInterface为interface类型时的情况,注意下面的图中步骤4、9中为了方便阅读,加了返回值,严格来说这是不合理,这么画的目的是为了方便阅读)
- HttpInvokerServiceExporter中有个俩个属性很重要,即service和serviceInterface,它的配置可以参考官方文档
- service是实际的服务类实例,是spring的bean;serviceInterface如果是interface接口类则生成动态代理(如果不是interface类型,则生成Cglib代理),表示服务类提供哪些服务——这个接口用于动态代理。
- HttpInvokerServiceExporter通过InitialzeBean来初始化必要的操作,这个操作在Spring中第一次对HttpInvokerServiceExporter进行getBean时进行。
2.HttpInvokerProxyFactoryBean
时序图(下图中步骤3、13、14中有返回值,这么画的目的是便于阅读;步骤4、16中方法上有参数,这么画严格来说不对的,这么画的目的仅是为了便于阅读):
- 由源代码可知,HttpInvokerProxyFactoryBean发送到HttpInvokerServiceExporter的是一个RemoteInvocation(如下图1所示)实例——包含methodName方法名、parameterTypes参数类型、实参。
- HttpInvokerServiceExporter返回给HttpInvokerProxyFactoryBean的是一个RemoteInvocationResult(如下图2所示)——包含一个execption属性(不为null则表示服务端处理发生异常)和一个Object类型的value属性(服务端业务上的处理结果)
图1 RemoteInvocation的属性
图2 RemoteInvocationResult的属性
注: 上述的描述跳过了很多步骤,这部分相对简单,建议自己去看源码。