ClassMode无法解析为变量

时间:2016-11-21 17:37:03

标签: spring-mvc junit

在我的java spring mvc应用程序中,我正在尝试使用Junit重置一组记录以进行测试。 但是在行:

@DirtiesContext(classMode=ClassMode.AFTER_EACH_TEST_METHOD)

抱怨:

ClassMode cannot be resolved to a variable

更新

我添加了

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-test</artifactId>
    <version>2.5</version>
</dependency>

然后它抱怨其他行

@ActiveProfiles("test")
@Sql(scripts="requests-dataset.sql") 
@DirtiesContext(classMode=ClassMode.AFTER_EACH_TEST_METHOD)

错误是:

    ActiveProfiles cannot be resolved to a type
Sql cannot be resolved to a type
Sql cannot be resolved to a type

1 个答案:

答案 0 :(得分:1)

首先,类名是DirtiesContext.ClassMode(它是DirtiesContext的嵌套类)。

其次,与任何其他类一样,必须导入它。

第三,作为javadoc shows,它存在于Spring 3.0之后。所以你不会在Spring 2.5中找到它。使用与您正在使用的其余spring框架库所使用的版本相同的spring-test版本。