【发布时间】:2014-07-27 11:12:21
【问题描述】:
我正在尝试使用 Maven 配置文件实例化休眠配置文件。我的配置文件位于src/main/resources 下,并且在 pom 文件中我标记了该文件夹以用于资源过滤。有趣的是,我可以从属性文件中加载相同的属性,而 hibernate 在解析配置文件时会抛出异常。这是我正在使用的代码示例。
POM - 资源过滤
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
文件结构
src/main/resources/hibernate.cfg.xml
src/main/resources/hibernate.properties
Maven 开发人员配置文件
<profile>
<id>dev</id>
<properties>
<hibernate.connection.url>jdbc:mysql://localhost:3306/example_schema?zeroDateTimeBehavior=convertToNull&UseUnicode=true&characterEncoding=utf8</hibernate.connection.url>
</properties>
</profile>
休眠配置文件示例
<property name="hibernate.connection.url">${hibernate.connection.url}</property>
属性文件示例
hibernate.config.file = ${hibernate.config.file}
当我运行我的应用程序时,我看到属性文件填充了正确的值;但是休眠配置文件会引发以下解析异常。
Caused by: org.dom4j.DocumentException: Error on line 1 of document : Content is not allowed in prolog. Nested exception: Content is not allowed in prolog.
at org.dom4j.io.SAXReader.read(SAXReader.java:482)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2155)
并且来自相同的堆栈跟踪
The reference to entity "UseUnicode" must end with the ';' delimiter. Nested exception: The reference to entity "UseUnicode" must end with the ';' delimiter.
但在 pom 中,我已经使用 &amp; 逃脱了 &。当我从 url 中删除查询参数时,它按预期工作,如何从 pom 文件中转义 & 符号?
【问题讨论】:
-
显然这是一个关于转义和字符的问题。删除该部分后,它没有任何问题。