java - 为什么我会收到此错误 访问 stax 流时出错
问题描述
错误消息:线程“main”中的异常 org.hibernate.HibernateException:访问 stax 流时出错此链接没有帮助我解决我的问题。我收到以下错误。我该怎么办?
Jul 26, 2018 4:44:24 AM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {5.3.3.Final}
Jul 26, 2018 4:44:24 AM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
Exception in thread "main" org.hibernate.HibernateException: Error accessing stax stream
at org.hibernate.boot.cfgxml.internal.JaxbCfgProcessor.unmarshal(JaxbCfgProcessor.java:107)
at org.hibernate.boot.cfgxml.internal.JaxbCfgProcessor.unmarshal(JaxbCfgProcessor.java:65)
at org.hibernate.boot.cfgxml.internal.ConfigLoader$2.run(ConfigLoader.java:62)
at org.hibernate.boot.cfgxml.internal.ConfigLoader$2.run(ConfigLoader.java:53)
at org.hibernate.boot.cfgxml.internal.ConfigLoader.loadConfigXmlResource(ConfigLoader.java:79)
at org.hibernate.boot.registry.StandardServiceRegistryBuilder.configure(StandardServiceRegistryBuilder.java:165)
at org.hibernate.cfg.Configuration.configure(Configuration.java:258)
at com.internship.java.HibernateTest.main(HibernateTest.java:16)
Caused by: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[8,1]
Message: Content is not allowed in prolog.
at com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl.next(XMLStreamReaderImpl.java:604)
at com.sun.xml.internal.stream.XMLEventReaderImpl.peek(XMLEventReaderImpl.java:276)
at org.hibernate.boot.cfgxml.internal.JaxbCfgProcessor.unmarshal(JaxbCfgProcessor.java:103)
... 7 more
以下代码是我的hibernate.cfg.xml
<?xml version="1.0" encoding="UTF-8"?>
<!-- ~ Hibernate, Relational Persistence for Idiomatic Java ~ ~ License:
GNU Lesser General Public License (LGPL), version 2.1 or later. ~ See the
lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-
2.1.html>. -->
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate
Configuration DTD 3.0//EN"
"classpath://org/hibernate/hibernate-configuration-3.0.dtd" >
-<hibernate-configuration>
-<session-factory>
<!-- Database connection settings -->
<property
name="connection.driver_class">org.postgresql94.Driver</property>
<property
name="connection.url">jdbc:postgresql://localhost:5432/postgres</property>
<property name="connection.username">postgres</property>
<property name="connection.password">password</property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
<!-- SQL dialect -->
<property
name="dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<!-- Disable the second-level cache -->
<property
name="cache.provider_class">org.hibernate.cache.internal.NoCacheProvider
</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
<!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto">create</property>
<mapping resource="org/hibernate/tutorial/hbm/Event.hbm.xml"/>
<mapping class="com.test.java.UserDetails"/>
</session-factory>
</hibernate-configuration>
请帮我解决这个问题。先感谢您。
解决方案
我通常会在类路径中有错误 XML 解析器的项目中收到此错误。
不幸的是,项目通常被大量的 XML 解析器臃肿。只需清洁它们。
你可以检查
- xml-api 罐子。只取 2.7.1 版本
- xerces / xercesImpl 相同:版本 2.7.1
- Saxon / Saxon9 :如果您将它与 java8 一起使用:您需要最低版本 9.7
推荐阅读
- bash - 如何使用 Bash 在另一个文本文件的末尾添加一列?
- c++ - 添加了 SDL 库:使用 VS 构建时“GNUC 未定义为预处理器宏”
- apache-kafka - 将消息加入 Kafka Stream 后从流中清除消息
- excel - 找到最后添加的工作表 (vba)?
- exception - NestJS:异常处理的最佳实践(异常过滤器 vs Interceptors.catchError)
- ruby-on-rails - 我应该将 Spree 中的所有控制器和路由复制/粘贴到我自己的应用程序吗?
- java - 在 64 位 C++ 中使用 JNI 时从 JAR 加载类失败
- c# - 如何从 MIME 内容创建图像?
- powershell - 如何获取与 0x1 或 0x4 匹配的 Powershell > Get-WinEvent > Security > Message > Access Mask
- objective-c - arc4random_uniform() 的奇怪结果。发生了什么