gpt4 book ai didi

java - Maven-单元配置文件中无法识别 Pom.xml 属性

转载 作者:行者123 更新时间:2023-12-01 22:45:33 24 4
gpt4 key购买 nike

我将数据库配置包含在 pom.xml 文件中,以便将它们用于我的项目测试,我正在使用unitils进行数据库集成我的 pom.xml 属性是

    <test.database.rules-satellite.driver>com.mysql.jdbc.Driver</test.database.rulessatellite.driver>
<test.database.rules-satellite.server>localhost</test.database.rules-satellite.server>
<test.database.rules-satellite.schema>R133_isp_copie_pdx</test.database.rules-satellite.schema>
<test.database.rules-satellite.url>jdbc:mysql://${test.database.rules-satellite.server}/${test.database.rules-satellite.schema}</test.database.rules-satellite.url>

<test.database.rules-satellite.username>junit</test.database.rules-satellite.username>
<test.database.rules-satellite.password>junit</test.database.rules-satellite.password>

我的unitils配置如下:

# Properties for the`enter code here` PropertiesDataSourceFactory
database.driverClassName=com.mysql.jdbc.Driver
database.url=jdbc:mysql://${test.database.rules-satellite.server}/${test.database.rules-satellite.schema}

# This property specifies the underlying DBMS implementation. Supported values are 'oracle', 'db2', 'mysql' and 'hsqldb'.
# The value of this property defines which vendor specific implementations of DbSupport and ConstraintsDisabler are chosen.
database.dialect=mysql

# user properties
database.userName=${test.database.rules-satellite.username}
database.password=${test.database.rules-satellite.password}
database.schemaNames=${test.database.rules-satellite.schema}

当我运行测试时,出现以下错误:

开始嵌套异常

java.net.UnknownHostException
MESSAGE: ${test.database.rules-satellite.server}

堆栈跟踪:

java.net.UnknownHostException: ${test.database.rules-satellite.server}
at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
at java.net.InetAddress$1.lookupAllHostAddr(InetAddress.java:849)
at java.net.InetAddress.getAddressFromNameService(InetAddress.java:1202)
at java.net.InetAddress.getAllByName0(InetAddress.java:1153)
at java.net.InetAddress.getAllByName(InetAddress.java:1083)
at java.net.InetAddress.getAllByName(InetAddress.java:1019)

我认为 Maven 属性没有被传播,这就是 unitils 无法识别它们的原因。

最佳答案

正如 Marcin Krasowski 所说,您需要使用资源插件,即只需添加

<build>
<resources>
<resource>
<directory>(path to the parent directory of your unitils conf file)</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>

默认情况下,Maven 不会替换所有文件中的 ${} 变量,您可以使用资源插件告诉它这样做。

关于java - Maven-单元配置文件中无法识别 Pom.xml 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25424889/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com