-1
我在Spring應用程序中遇到了一個奇怪的行爲。爲什麼我不能在我的項目中使用@Before註釋? 「以前不能解析爲類型」
我想創建一個JUnit測試類是這樣的:
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);
}
}
的主要問題是,我獲得的設置()方法@Before標註錯誤。這對我說:之前不能被解析爲一個類型
它似乎無法找到該@Before註解的依賴。
這是我在我的的pom.xml文件的依賴性:
<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>
我缺少什麼?哪裏不對?我該如何解決這個問題?
你有導入聲明嗎?你知道,最後任何註釋都只是一個java類;所以你需要的東西,使他們的工作:1)一個jar /類文件和2)在你自己的代碼 – GhostCat
嘗試一個Ctrl + Shift + O(Windows)或cmd + shift + O(mac)組織導入(在月食或STS上) – ddb
我無法導入這個特定的陳述。它對我說「以前創建註釋」,所以這意味着我沒有依賴mu依賴 – AndreaNobili