[英]Maven resource filtering not working on Spring configuration XML file wiith tests
[英]Maven Profiles, Resource Filtering with hibernate configuration file
我正在嘗試使用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>
Hibernate配置文件示例
<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我已經逃避&
與&
。 當我從url中刪除查詢參數時,它可以按預期運行,如何從pom文件中刪除&符號?
我不確定它會解決您的問題。 但是,您可以查看以下URL:-http: //maven.apache.org/guides/introduction/introduction-to-profiles.html
或這個:-
它被很好地解釋了。 我無權發表評論,這就是我要回答的原因。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.