我在 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 无法识别它们的原因。