我有一个场景,我必须根据部署应用程序的环境将不同的方言、提供程序加载到我的 persistence.xml 文件中。
例如
在一个环境中我使用 Oracle11g,而在另一个环境中我使用 MySql8。我希望我的 persistnece.xml 看起来像这样。
<persistence-unit name="firstPU" transaction-type="RESOURCE_LOCAL">
<provider>${somekey.provider}</provider>
<properties>
<property name="hibernate.dialect" value="${somekey.dialect}" />
</properties>
</persistence-unit>
然后有两个单独的属性文件(first.property,second.property)并使用我的 pom.xml 中的构建配置文件选择其中一个。例如-
<profile>
.
.
.
<build>
<resources>
<resource>
<directory>src/main/resources/config/${build.profile.id}</directory>
<excludes>
<exclude>**/first.properties</exclude>
</excludes>
</resource>
</resources>
</build>
.
.
.
</profile>
因此,根据选择的配置文件,它将排除一个 .property 文件并从另一个文件中读取。
所有这一切的问题是值从属性文件返回为空。(不再)
我在这里遗漏了什么还是有更好的方法来做这种事情?
更新 -
这对于阅读方言值很有效。但是,我无法阅读 Provider !
是否也可以从属性文件中读取 Provider 值?