【问题标题】:Maven Profiles, Resource Filtering with hibernate configuration fileMaven 配置文件,使用休眠配置文件进行资源过滤
【发布时间】: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&amp;UseUnicode=true&amp;characterEncoding=utf8</hibernate.connection.url>
    </properties>
</profile>

休眠配置文件示例

&lt;property name="hibernate.connection.url"&gt;${hibernate.connection.url}&lt;/property&gt;

属性文件示例

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;amp; 逃脱了 &amp;。当我从 url 中删除查询参数时,它按预期工作,如何从 pom 文件中转义 & 符号?

【问题讨论】:

  • 显然这是一个关于转义和字符的问题。删除该部分后,它没有任何问题。

标签: java hibernate maven


【解决方案1】:

我不确定它是否能解决您的问题。 但是,您可以查看以下 URL:- http://maven.apache.org/guides/introduction/introduction-to-profiles.html

或者这个:-

http://www.manydesigns.com/en/portofino/portofino3/tutorials/using-maven-profiles-and-resource-filtering

解释得很漂亮。 我无权发表评论,这就是我要回答的原因。

【讨论】:

  • 实际上我已经检查了这些链接,并且我希望它能够工作。还是谢谢
猜你喜欢
  • 2016-01-27
  • 2013-04-26
  • 2017-04-27
  • 2017-04-30
  • 1970-01-01
  • 1970-01-01
  • 2017-01-20
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多