前几天用xfire开发了个接口,本来在工程可以访问互联网的情况下没有任何问题的,但昨天部署到客户的内网环境就出问题了,异常如下:
javax.faces.FacesException: java.net.UnknownHostException: www.springframework.org
找不到主机www.springframework.org,因为不能访问互联网
找到问题出处,在xfire的配置文件/WEB-INF/xfire-servlet.xml,该文件内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<!-- 引入XFire预配置信息 -->
<import resource="classpath:org/codehaus/xfire/spring/xfire.xml" />
<!-- 定义访问的url -->
<bean
class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="urlMap">
<map>
<entry key="/WSPersonsInfoService.ws">
<ref bean="WSPersonsInfoService" />
</entry>
</map>
</property>
</bean>
<!-- 使用XFire导出器 -->
<bean id="baseWebService"
class="org.codehaus.xfire.spring.remoting.XFireExporter"
lazy-init="false" abstract="true">
<!-- 引用xfire.xml中定义的工厂 -->
<property name="serviceFactory" ref="xfire.serviceFactory" />
<!-- 引用xfire.xml中的xfire实例 -->
<property name="xfire" ref="xfire" />
</bean>
<bean id="WSPersonsInfoService" parent="baseWebService">
<!-- 业务服务bean -->
<property name="serviceBean" ref="WSPersonsInfoImp" />
<!-- 业务服务bean的窄接口类 -->
<property name="serviceClass"
value="com.ws.yxjsry.IWSPersonsInfo" />
</bean>
<bean id="WSPersonsInfoImp"
class="com.ws.yxjsry.WSPersonsInfoImp" />
</beans>
问题就出在
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
在不能访问互联网的条件下访问不了http://www.springframework.org/dtd/spring-beans.dtd
解决方案尝试:
在网上找了半天,很多说把DOCTYPE改为访问本地文件,如:
<!DOCTYPE beans SYSTEM "spring-beans.dtd">
需要把spring-beans.dtd文件放在classpath目录下,例如tomcat的tomcat/bin/目录下。
修改后启动,发现仍然报找不到主机www.springframework.org,仔细查找后发现原因是在xfire-servlet.xml里面有一行<import resource="classpath:org/codehaus/xfire/spring/xfire.xml" />
在xfire.xml中存在
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
而且在xfire.xml中还有引用另一个xml文件
<import resource="customEditors.xml"/>
customEditors.xml中也存在
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
因为xfire.xml和customEditors.xml在xfire-all-1.2.6,jar里面,不想对JAR包作修改,于是,我就想到了把,xfire.xml和customEditors.xml的内容直接复制到xfire-servlet.xml里面,把引用<import resource="classpath:org/codehaus/xfire/spring/xfire.xml" />
去掉,问题就可以解决了,修改后的xfire-servlet.xml如下:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans SYSTEM "spring-beans.dtd">
<!-- 引入XFire预配置信息 -->
<bean id="xfire.customEditorConfigurer"
class="org.springframework.beans.factory.config.CustomEditorConfigurer">
<property name="customEditors">
<map>
<entry
key="org.codehaus.xfire.service.ServiceFactory">
<bean
class="org.codehaus.xfire.spring.editors.ServiceFactoryEditor">
<property name="transportManager"
ref="xfire.transportManager" />
</bean>
</entry>
</map>
</property>
</bean>
<bean id="xfire.serviceRegistry"
class="org.codehaus.xfire.service.DefaultServiceRegistry"
scope="singleton" />
<bean id="xfire.transportManager"
class="org.codehaus.xfire.transport.DefaultTransportManager"
scope="singleton" init-method="initialize" destroy-method="dispose">
</bean>
<bean id="xfire" class="org.codehaus.xfire.DefaultXFire"
scope="singleton">
<constructor-arg index="0">
<ref bean="xfire.serviceRegistry" />
</constructor-arg>
<constructor-arg index="1">
<ref bean="xfire.transportManager" />
</constructor-arg>
</bean>
<bean id="xfire.typeMappingRegistry"
class="org.codehaus.xfire.aegis.type.DefaultTypeMappingRegistry"
init-method="createDefaultMappings" scope="singleton">
</bean>
<bean id="xfire.aegisBindingProvider"
class="org.codehaus.xfire.aegis.AegisBindingProvider"
scope="singleton">
<constructor-arg index="0">
<ref bean="xfire.typeMappingRegistry" />
</constructor-arg>
</bean>
<bean id="xfire.serviceFactory"
class="org.codehaus.xfire.service.binding.ObjectServiceFactory"
scope="singleton">
<constructor-arg index="0">
<ref bean="xfire.transportManager" />
</constructor-arg>
<constructor-arg index="1">
<ref bean="xfire.aegisBindingProvider" />
</constructor-arg>
</bean>
<bean id="xfire.servletController"
class="org.codehaus.xfire.transport.http.XFireServletController"
scope="singleton">
<constructor-arg>
<ref bean="xfire" />
</constructor-arg>
</bean>
<bean id="xfire.messageServiceFactory"
class="org.codehaus.xfire.service.binding.ObjectServiceFactory">
<constructor-arg index="0" ref="xfire.transportManager" />
<constructor-arg index="1" ref="xfire.messageBindingProvider" />
<property name="style" value="message" />
</bean>
<bean id="xfire.messageBindingProvider"
class="org.codehaus.xfire.service.binding.MessageBindingProvider" />
<!-- 定义访问的url -->
<bean
class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="urlMap">
<map>
<entry key="/WSPersonsInfoService.ws">
<ref bean="WSPersonsInfoService" />
</entry>
</map>
</property>
</bean>
<!-- 使用XFire导出器 -->
<bean id="baseWebService"
class="org.codehaus.xfire.spring.remoting.XFireExporter"
lazy-init="false" abstract="true">
<!-- 引用xfire.xml中定义的工厂 -->
<property name="serviceFactory" ref="xfire.serviceFactory" />
<!-- 引用xfire.xml中的xfire实例 -->
<property name="xfire" ref="xfire" />
</bean>
<bean id="WSPersonsInfoService" parent="baseWebService">
<!-- 业务服务bean -->
<property name="serviceBean" ref="WSPersonsInfoImp" />
<!-- 业务服务bean的窄接口类 -->
<property name="serviceClass"
value="com.ws.yxjsry.IWSPersonsInfo" />
</bean>
<bean id="WSPersonsInfoImp"
class="com.ws.yxjsry.WSPersonsInfoImp" />
</beans>
后来觉得要在classpath中放spring-beans.dtd文件太麻烦,就想到用spring2.x的schema方式,这样就不需要spring-beans.dtd文件了。方法是把<!DOCTYPE beans SYSTEM "spring-beans.dtd">去掉,把<beans>修改成
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
当然,工程中用到的spring包要换成用2.0以上的,否则回报错
org.xml.sax.SAXParseException: Document is invalid: no grammar found.
org.xml.sax.SAXParseException: Document root element "beans", must match DOCTYPE root "null".
问题总结:
问题关键是xfire1.2.6的XML定义格式是按照spring1.x格式的,而且dtd都是在网络上校验,所以在不能访问互联网的环境中就会报错。首先,需要把xfire.xml和customEditors.xml复制到xfire-servlet.xml中。
然后,
如果工程用的是spring1.x,就把spring-beans.dtd文件放在classpath目录下,修改DOCTYPE为<!DOCTYPE beans SYSTEM "spring-beans.dtd">
如果工程用的是spring2.x,就把<!DOCTYPE beans SYSTEM "spring-beans.dtd">去掉,把<beans>修改成
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
附件中有xfire的包和spring-beans.dtd文件
分享到:
相关推荐
XFire1.2.6完整版JAR包 XFire1.2.6完整版JAR包XFire1.2.6完整版JAR包XFire1.2.6完整版JAR包
xfire-1.2.6.rar xfire-1.2.6.rar xfire-1.2.6.rar
解决了Spring2.0和XFire1.2.6整合出错的问题 如果你觉得我骗分请不要下,谢谢!
xfire1.2.6_plugin eclipse插件
Xfire1.2.6版API手册.chmXfire1.2.6版API手册.chmXfire1.2.6版API手册.chmXfire1.2.6版API手册.chm
xfire1.2.6 源代码 源文件 源程序。供调试、研究用。
xfire 1.2.6版本文件,使用方便。 .
xfire1.2.6 ws-security示例,也就是让里面的例子跑起来,网上都没这个教程,所以我就花了点点时间做了一下
XFire 1.2.6调用Web Service的几种方法
去除xfire传递date类型的数据时值为null时的异常的jar包
基于webservice的开发,XFire需要的jar文件。
spring3.0整合Xfire1.2.6 开发webservice需要的jar包
xfire-distribution-1.2.6.zip
xfire-distribution-1.2.6.zip
xfire 1.2.6 API帮助文档
xfire1.2.6的myeclipse插件
xfire-1.2.6 jar包——webserver必备。。。。。。。。。。。
1、在Springmvc中放入xfire1.2.6jar,按照注解的方式配置后,springMVC启动不会扫描collection,后面修改了配置方式,web.xml使用org.codehaus.xfire.transport.http.XFireConfigurableServlet,xfire/services.xml...
xfire1.2.6+spring2.5整合,导入到myeclipse就可以运行,通过调用接口来调用。