首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >DBUnit :从maven设置属性

DBUnit :从maven设置属性
EN

Stack Overflow用户
提问于 2015-07-31 10:03:28
回答 1查看 188关注 0票数 1

要使用DBunit,必须设置一些属性。它们可以通过代码或maven属性直接设置。

我使用的是DBunit 2.4.9,通过maven设置它会有麻烦。我检查了pom.xml从DBunit,这是存在的:

代码语言:javascript
复制
<systemProperties>
        ....
        <property>
          <name>dbunit.profile.driverClass</name>
          <value>${dbunit.profile.driverClass}</value>
        </property>

我尝试过从settings.xml或项目pom.xml设置这个属性,但是我仍然得到了这个异常:DbAssertionFailedError: driverClass is null

下面是我在pom.xml上设置的属性(在根级):

代码语言:javascript
复制
<properties>
    <dbunit.profile.driverClass>org.postgresql.Driver</dbunit.profile.driverClass>
    <dbunit.profile.url>jdbc:postgresql://localhost:5432/tests</dbunit.profile.url>
    <dbunit.profile.user>postgres</dbunit.profile.user>
    <dbunit.profile.password>postgres</dbunit.profile.password>
/properties>

我对maven很陌生,所以我想我错过了一些东西

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-08-03 12:46:14

我已经想明白了。问题来自于POM.xml和实际代码之间不存在的属性名称。例如,代码依赖于属性dbunit.driverClass,而DBunit POM.xml在属性中包含以下行:

代码语言:javascript
复制
<property>
  <name>dbunit.profile.driverClass</name>
  <value>${dbunit.profile.driverClass}</value>
</property>

我对maven-failsafe-plugin进行了以下配置:

代码语言:javascript
复制
<configuration>
    <systemPropertyVariables>
        <dbunit.driverClass>${dbunit.profile.driverClass}</dbunit.driverClass>
        <dbunit.connectionUrl>${dbunit.profile.url}</dbunit.connectionUrl>
        <dbunit.username>${dbunit.profile.user}</dbunit.username>
        <dbunit.password>${dbunit.profile.password}</dbunit.password>
    </systemPropertyVariables>
</configuration>

如果你有更好的解决办法,我愿意接受建议

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31743495

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档