问题描述: 使用Xfire + spring 开发webservice时,在远程调用webservice会提示注入的对象NULL。
解决办法:不要把webservice的提供类添加到bean中(以HelloWebserviceImpl为例)。
在HelloWebserviceImpl类中获取spring的context。使用ClassPathXmlApplicationContext获取, 添加下面的语句
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");
得到了context后就可以获取你想得到的bean对象了。
问题可能出现的原因:每次访问Webservice服务时,HelloWebserviceImpl都会被重新创建。 而没有使用到spring的bean,注入失败。