我们正在进行灾难恢复练习,并且有几个Hibernate Spring应用程序没有开始跟随错误
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method Failed; nested exception is org.hibernate.InvalidMappingException: Could not parse mapping document from input stream
at org.springframework.beans.factory.support.AbstractAutowireCapablebeanfactory.initializeBean(AbstractAutowireCapablebeanfactory.java:1337)
at org.springframework.beans.factory.support.AbstractAutowireCapablebeanfactory.doCreateBean(AbstractAutowireCapablebeanfactory.java:473)
at org.springframework.beans.factory.support.AbstractAutowireCapablebeanfactory$1.run(AbstractAutowireCapablebeanfactory.java:409)
at java.security.AccessController.doPrivileged(AccessController.java:214)
at org.springframework.beans.factory.support.AbstractAutowireCapablebeanfactory.createBean(AbstractAutowireCapablebeanfactory.java:380)
at org.springframework.beans.factory.support.Abstractbeanfactory$1.getObject(Abstractbeanfactory.java:264)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:221)
at org.springframework.beans.factory.support.Abstractbeanfactory.doGetBean(Abstractbeanfactory.java:261)
at org.springframework.beans.factory.support.Abstractbeanfactory.getBean(Abstractbeanfactory.java:185)
at org.springframework.beans.factory.support.Abstractbeanfactory.getBean(Abstractbeanfactory.java:164)
at org.springframework.beans.factory.support.AbstractAutowireCapablebeanfactory.autowireByName(AbstractAutowireCapablebeanfactory.java:1029)
at org.springframework.beans.factory.support.AbstractAutowireCapablebeanfactory.populateBean(AbstractAutowireCapablebeanfactory.java:977)
at org.springframework.beans.factory.support.AbstractAutowireCapablebeanfactory.doCreateBean(AbstractAutowireCapablebeanfactory.java:472)
... 55 more
Caused by: org.hibernate.InvalidMappingException: Could not parse mapping document from input stream
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:541)
at org.springframework.orm.hibernate3.LocalSessionfactorybean.buildSessionFactory(LocalSessionfactorybean.java:638)
at org.springframework.orm.hibernate3.AbstractSessionfactorybean.afterPropertiesSet(AbstractSessionfactorybean.java:211)
at org.springframework.beans.factory.support.AbstractAutowireCapablebeanfactory.invokeInitMethods(AbstractAutowireCapablebeanfactory.java:1368)
at org.springframework.beans.factory.support.AbstractAutowireCapablebeanfactory.initializeBean(AbstractAutowireCapablebeanfactory.java:1334)
... 67 more
**Caused by: org.dom4j.DocumentException: Server returned HTTP response code: 504 for URL: http://www.jboss.org/dtd/hibernate/hibernate-mapping-3.0.dtd Nested exception: Server returned HTTP response code: 504 for URL: http://www.jboss.org/dtd/hibernate/hibernate-mapping-3.0.dtd**
at org.dom4j.io.SAXReader.read(SAXReader.java:484)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:532)
... 71 more
hbm映射XML文件有
在SO和Hibernate论坛上搜索修复看起来我们需要在doctype到SYSTEM中创建DTD所以它从本地系统读取而不是在sourceforge.net上托管的公共dtd
但是这个Hibernate正在寻找appserver根文件夹上的文件
Caused by: org.hibernate.InvalidMappingException: Could not parse mapping document from input stream
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:541)
at org.springframework.orm.hibernate3.LocalSessionfactorybean.buildSessionFactory(LocalSessionfactorybean.java:638)
at org.springframework.orm.hibernate3.AbstractSessionfactorybean.afterPropertiesSet(AbstractSessionfactorybean.java:211)
at org.springframework.beans.factory.support.AbstractAutowireCapablebeanfactory.invokeInitMethods(AbstractAutowireCapablebeanfactory.java:1368)
at org.springframework.beans.factory.support.AbstractAutowireCapablebeanfactory.initializeBean(AbstractAutowireCapablebeanfactory.java:1334)
... 72 more
Caused by: org.dom4j.DocumentException: C:\IBMSOA\SDP70\runtimes\base_v61\profiles\AppSrvWSFP01\hibernate-mapping-3.0.dtd (The system cannot find the file specified.) Nested exception: C:\IBMSOA\SDP70\runtimes\base_v61\profiles\AppSrvWSFP01\hibernate-mapping-3.0.dtd (The system cannot find the file specified.)
at org.dom4j.io.SAXReader.read(SAXReader.java:484)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:532)
... 76 more
如何指定SYSTEM DTD引用,以便Hibernate从hibernate.jar读取DTD而不是在文件系统中查找它?
最佳答案
查看DTDEntityResolver http://grepcode.com/file/repo1.maven.org/maven2/org.hibernate/hibernate-core/3.3.1.GA/org/hibernate/util/DTDEntityResolver.java#DTDEntityResolver的hibernate源代码,下面为我们工作
原文链接:https://www.f2er.com/spring/432496.html
耶和开源!