dom4j在联网能正常解析,断网时解析报错的处理方法



启动TOMCAT服务器报错如下

2016-10-13 16:08:31[ERROR](Configuration.java:1222) problem parsing configurationfile:/E:/Program%20Files%20(x86)/Tomcat%208.0/webapps/autotest/WEB-INF/classes/hibernate.cfg.xml
org.dom4j.DocumentException: www.hibernate.org Nested exception:www.hibernate.org
 at org.dom4j.io.SAXReader.read(SAXReader.java:484)
 at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1218)
 at org.hibernate.cfg.Configuration.configure(Configuration.java:1177)
 at org.springframework.orm.hibernate3.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:523)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1114)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:349)


原因:

hibernate.cfg.xml文件中使用了http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd ,没联网时找不到hibernate-configuration-3.0.dtd文件

原代码如下:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
  "-//Hibernate/Hibernate Configuration DTD//EN"
  "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
 <session-factory>


解决办法:

hibernate-configuration-3.0.dtd 下载到本地   ,放到和hibernate.cfg.xml 同个文件夹下,把代码修改为:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
  "-//Hibernate/Hibernate Configuration DTD//EN"
  "hibernate-configuration-3.0.dtd">

<hibernate-configuration>
 <session-factory>

        <property name="connection.driver_class">com.mysql.jdbc.Driver</property>






成功解决问题。

文件下载地址:http://hibernate.org/dtd/

备注:testcaseBO.hbm.xml的文件头不需要任何修改

<?xml version="1.0" encoding='UTF-8'?>
<!DOCTYPE hibernate-mapping PUBLIC
 "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
 "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >

<hibernate-mapping package="common.model">


参考资料:

http://lazycat774880994.iteye.com/blog/641143




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值