【问题标题】:NoClassDefFoundError with Spring 3.1 Controller Unit Test带有 Spring 3.1 控制器单元测试的 NoClassDefFoundError
【发布时间】:2012-09-17 19:31:43
【问题描述】:

我有一个简单的autowired 控制器和一个测试。当项目使用 mvn 和代码覆盖目标 emma:emma 和 emma:check 构建时,测试用例失败并出现以下错误。

简单的“mvn test”命令成功。 “mvn test emma:emma emma:check”失败。

java.lang.NoClassDefFoundError: org/springframework/web/bind/support/WebDataBinderFactory

【问题讨论】:

    标签: spring model-view-controller junit4 noclassdeffounderror


    【解决方案1】:

    尝试使用 cobertura,将其添加到您的报告部分:

    <reporting>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>cobertura-maven-plugin</artifactId>
                <version>2.5.1</version>
                <configuration>
                  <check>
                    <lineRate>120</lineRate>
                  </check>
                </configuration>
            </plugin>
        </plugins>
    </reporting>
    

    然后做:

    mvn site
    

    然后在浏览器中打开:

    target/site/index.html
    

    您将在那里看到 cobertura 报告。 最好将这类插件添加到您的父 pom 中。

    【讨论】:

      【解决方案2】:

      你在测试中是否有 spring-web 的依赖。如果没有,那么尝试添加对org.springframework:spring-web的依赖

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-07-31
        • 1970-01-01
        • 2011-01-30
        • 2016-07-25
        • 2019-07-11
        相关资源
        最近更新 更多