2016-11-21 88 views
0

在我的java spring mvc應用程序中,我試圖重置一堆用於Junit測試的記錄。 但行:ClassMode無法解析爲變量

@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 

回答

0

首先,類名是DirtiesContext.ClassMode(這是一個嵌套類DirtiesContext的)。

其次,作爲任何其他類,它必須導入。

第三,作爲javadoc shows,它自Spring 3.0以來就存在。所以你不會在Spring 2.5中找到它。使用與您正在使用的其他彈簧框架庫相同版本的spring-test。