我将数据库配置包含在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无法识别它们的原因。
最佳答案
您需要使用带有过滤选项的Maven资源插件。可以在这里找到更详细的解释:http://www.manydesigns.com/en/portofino/portofino3/tutorials/using-maven-profiles-and-resource-filtering/#TOC-Resource-filtering
关于java - 在unitils配置文件中无法识别Maven- Pom.xml属性,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25424889/