一、概述
首先说明下,该问题的主要原因是Spring管理service(通过xml读取service,利用反射创建实例),在controller使用的时候,由于Controller里面注入了service,但实际并没有找到service的实例化,问题是applicationContext-Service.xml中,没有配置我所注入service,所以没有办法实例化,导致出错。我的项目中使用的Hessian协议进行调用,在客户端没有引入Service配置导致的原因。
二、解决方法
如果使用hessian或者是dubbo进行调用的话,一定要在服务端和客户端都要注册Service实例。
例如:
服务端
<bean id="pictureClient"
class="org.springframework.remoting.caucho.HessianProxyFactoryBean">
<property name="serviceUrl">
<value>
http://127.0.0.1:9501/remoting/PictureRemoting
</value>
</property>
<property name="serviceInterface">
<value>com.popchinese.usercenter.service.PictureService</value>
</property>
</bean>
客户端
<bean id="pictureClient"
class="org.springframework.remoting.caucho.HessianProxyFactoryBean">
<property name="serviceUrl">
<value>
http://127.0.0.1:9501/remoting/PictureRemoting
</value>
</property>
<property name="serviceInterface">
<value>com.popchinese.usercenter.service.PictureService</value>
</property>
</bean>