首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 互联网 >

xfire1.2.6不能访问互联网环境上的有关问题及解决方案

2012-11-16 
xfire1.2.6不能访问互联网环境下的问题及解决方案前几天用xfire开发了个接口,本来在工程可以访问互联网的

xfire1.2.6不能访问互联网环境下的问题及解决方案
前几天用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/></entry></map></property></bean><!-- 使用XFire导出器 --><bean id="baseWebService"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"/></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"/></bean></entry></map></property></bean><bean id="xfire.serviceRegistry"/><bean id="xfire.transportManager"init-method="initialize" destroy-method="dispose"></bean><bean id="xfire" /></constructor-arg><constructor-arg index="1"><ref bean="xfire.transportManager" /></constructor-arg></bean><bean id="xfire.typeMappingRegistry"scope="singleton"></bean><bean id="xfire.aegisBindingProvider"/></constructor-arg></bean><bean id="xfire.serviceFactory"/></constructor-arg><constructor-arg index="1"><ref bean="xfire.aegisBindingProvider" /></constructor-arg></bean><bean id="xfire.servletController"/></constructor-arg></bean><bean id="xfire.messageServiceFactory"ref="xfire.transportManager" /><constructor-arg index="1" ref="xfire.messageBindingProvider" /><property name="style" value="message" /></bean><bean id="xfire.messageBindingProvider"/><!-- 定义访问的url --><bean/></entry></map></property></bean><!-- 使用XFire导出器 --><bean id="baseWebService"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"/></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文件

热点排行