2016-07-06 1 views
-1

私は、奇妙な動作がSpringアプリケーションに発生しています。私はこのようなJUnitテストクラスを作成しようとしていますプロジェクトで@Before注釈を使用できないのはなぜですか? "前に型に解決できません"

public class AppTest { 

@Before 
public void setUp() { 
    // Create the application from the configuration 
    ApplicationContext context = new AnnotationConfigApplicationContext(ApplicationConfig.class) 
    // Look up the application service interface 
    service = (TransferService) context.getBean(TransferService.class); 
    } 

} 

主な問題は、私はのsetUp()メソッド@Before注釈にエラーを得ることです。タイプ

に解決することはできません前に、それは@Before注釈の依存関係を見つけることができないように思え:それはことを私に言います。私は何をしないのです

<properties> 
    <org.springframework.version>3.2.16.RELEASE</org.springframework.version> 
</properties> 


<dependencies> 

    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-expression</artifactId> 
     <version>${org.springframework.version}</version> 
    </dependency> 

    <!-- Bean Factory and JavaBeans utilities (depends on spring-core) Define 
     this if you use Spring Bean APIs (org.springframework.beans.*) --> 
    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-beans</artifactId> 
     <version>${org.springframework.version}</version> 
    </dependency> 


    <!-- Core utilities used by other modules. Define this if you use Spring 
     Utility APIs (org.springframework.core.*/org.springframework.util.*) --> 

    <!-- Aspect Oriented Programming (AOP) Framework (depends on spring-core, 
     spring-beans) Define this if you use Spring AOP APIs (org.springframework.aop.*) --> 
    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-aop</artifactId> 
     <version>${org.springframework.version}</version> 
    </dependency> 

    <!-- Application Context (depends on spring-core, spring-expression, spring-aop, 
     spring-beans) This is the central artifact for Spring's Dependency Injection 
     Container and is generally always defined --> 
    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-context</artifactId> 
     <version>${org.springframework.version}</version> 
    </dependency> 

    <!-- Various Application Context utilities, including EhCache, JavaMail, 
     Quartz, and Freemarker integration Define this if you need any of these integrations --> 
    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-context-support</artifactId> 
     <version>${org.springframework.version}</version> 
    </dependency> 

    <!-- Transaction Management Abstraction (depends on spring-core, spring-beans, 
     spring-aop, spring-context) Define this if you use Spring Transactions or 
     DAO Exception Hierarchy (org.springframework.transaction.*/org.springframework.dao.*) --> 
    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-tx</artifactId> 
     <version>${org.springframework.version}</version> 
    </dependency> 

    <!-- JDBC Data Access Library (depends on spring-core, spring-beans, spring-context, 
     spring-tx) Define this if you use Spring's JdbcTemplate API (org.springframework.jdbc.*) --> 
    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-jdbc</artifactId> 
     <version>${org.springframework.version}</version> 
    </dependency> 

    <!-- 
    <dependency> 
     <groupId>FTP-MANAGER</groupId> 
     <artifactId>FTP-MANAGER</artifactId> 
     <version>0.0.1-SNAPSHOT</version> 
    </dependency> 
    --> 

    <dependency> 
     <groupId>javax.mail</groupId> 
     <artifactId>mail</artifactId> 
     <version>1.4</version> 
    </dependency> 

    <dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <version>3.8.1</version> 
     <scope>test</scope> 
    </dependency> 

    <dependency> 
     <groupId>log4j</groupId> 
     <artifactId>log4j</artifactId> 
     <version>1.2.16</version> 
    </dependency> 

    <!-- JDBC 3.0 driver for Microsoft SQL Server and Sybase --> 
    <dependency> 
     <groupId>net.sourceforge.jtds</groupId> 
     <artifactId>jtds</artifactId> 
     <version>1.2.4</version> 
    </dependency> 

    <!-- Contiene la classe BasicDataSource --> 
    <dependency> 
     <groupId>commons-dbcp</groupId> 
     <artifactId>commons-dbcp</artifactId> 
     <version>1.4</version> 
    </dependency> 
</dependencies> 

これは私が私ののpom.xmlファイルを持っている依存関係がありますか?なにが問題ですか?この問題を解決するにはどうすればよいですか?

+1

インポートステートメントがありますか?最後に、注釈はJavaクラスに過ぎません。 1)jar/classファイルと2)自分のコードのimport文 – GhostCat

+0

ctrl + shift + O(windows)またはcmd + shift + O(mac)を試してインポートを整理してください(EclipseまたはSTSで) – ddb

+0

この特定の文章をインポートすることはできません。それは私に "Before annotation Before"を作成するように言います。つまり、私がmu依存になっていないことを意味します。 – AndreaNobili

答えて

5

@Beforeは、junit 4.xから入手できます。新しいバージョンのJunitに変更してください。

<dependency> 
    <groupId>junit</groupId> 
    <artifactId>junit</artifactId> 
    <version>4.11</version> 
    <scope>test</scope> 
</dependency> 
関連する問題