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

来源:互联网 发布:淘宝上架宝贝教程2017 编辑:程序博客网 时间:2024/06/07 05:42


启动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




0 0
原创粉丝点击