Tomcat发布WebService
需求:
有多个层级的多个平台需要数据交互,所以就用到了WebService,因为原有的项目是用Tomcat部署的,所以也必须在Tomcat下部署一个WebService。
准备:
下载jar包:http://xfire.codehaus.org/Download
jar包说明:
xfire-all-1.2.6.jar 这个是核心包,所有其他包的版本都要和这个兼容
xbean-spring-2.8.jar 这个也只能是这个版本,其他版本报错,例如2.7
jdom-1.0.jar 这个最好是1.0,我试了2.0报错
wsdl4j-1.6.1.jar 解析wsdl的jar包
貌似这几个是必要的,反正在我的项目里是必要的,少一个就报错,其实也不必担心jar包版本的问题,你下载了压缩文件之后里面都有这些相应的jar包
注意:
1、service.xml 的位置和写法:
service.xml 要放在src下面的 META-INF/xfire 下面以保证它可以编译到 WEB-INF/classes/META-INF/xfire 下面
service.xml 在写命名空间的时候要注意,如果你按照下面这种写法可能会报错:
<beans xmlns="http://xfire.codehaus.org/config/1.0"> <service > <name>smsservice</name> <serviceClass>com.smsweb.www.webservice.ISmsService</serviceClass> <implementationClass>com.smsweb.www.webservice.impl.SmsServiceImpl</implementationClass> <style>wrapped</style> <use>literal</use> <scope>application</scope> </service>
可能报的错误:
org.springframework.beans.factory.BeanDefinitionStoreException:Unrecognized xbean element mapping: bean in namespace http://xfire.codehaus.org/config/1.0
要改一下service.xml 的写法,如下:
<beans> <service xmlns="http://xfire.codehaus.org/config/1.0"> <name>smsservice</name> <serviceClass>com.smsweb.www.webservice.ISmsService</serviceClass> <implementationClass>com.smsweb.www.webservice.impl.SmsServiceImpl</implementationClass> <style>wrapped</style> <use>literal</use> <scope>application</scope> </service>
把命名空间从 <bean> 标签改写到 <service xmlns="http://xfire.codehaus.org/config/1.0">,据说是因为当前用的spring,不认得这个标注方式。
篇外:
过程中因为service.xml 中的<scope>写成了<sope>结果Spring提示:
是不是灰常强大!
P:感谢冷 水 泡 茶的错误指正!