JPA / Maven:如何在Maven项目的构建时为Persistance.xml提供价值?

问题描述 投票:0回答:1

以下是我的persistance.xml:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.2"
    xmlns="http://xmlns.jcp.org/xml/ns/persistence"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_2.xsd">

    <persistence-unit name="IntegratorMasterdataDS"
        transaction-type="JTA">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
<!--        <jta-data-source>java:/datasources/IDS1</jta-data-source>  -->
        <jta-data-source>java:/datasources/IDS</jta-data-source>
        <properties>
            <property name="hibernate.archive.autodetection" value="class" />
            <property name="hibernate.show_sql" value="true" />
            <property name="hibernate.format_sql" value="true" />
            <property name="hibernate.generate_statistics" value="true"/>
        </properties>
    </persistence-unit>
</persistence>

当我需要使用生产资料进行构建时,我需要在persistance.xml中进行注释和取消注释。

maven构建中是否有任何方法可以在运行时在persistance.xml中提供值? (我记得在旧项目中我看到了{something.some},但找不到用例中的用法?)

hibernate maven jpa persistence.xml maven-profiles
1个回答
0
投票

将persistence.xml定位到src / main / resources / PATH之类的位置,然后使用过滤。将标签添加到POM并将其设置为true,如下所示:Details Here

<resource>
        <directory>src/main/resources</directory>
        <filtering>true</filtering>
      </resource>
© www.soinside.com 2019 - 2024. All rights reserved.