我學習春天從本教程:的ApplicationContext進口春天
http://courses.caveofprogramming.com/courses/the-java-spring-tutorial/lectures/38024
在本教程中,講師下載春天在3.2.3版本的依賴關係(彈簧豆,春天背景,彈簧芯) 。發佈。
然後寫入驗證碼:
package com.caveofprogramming.spring.test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
public class App {
public static void main(String[] args) {
ApplicationContext context = new FileSystemXmlApplicationContext("beans.xml");
Person person = (Person)context.getBean("person");
person.speak();
}
}
當我使用:彈簧背景下,彈簧豆類和彈簧核心在最後一個版本4.3.3.RELEASE然後ApplicationContext的進口不起作用。它在我將其更改爲舊版本時起作用。 「不起作用」意味着當我編寫「ApplicationContext context = new FileSystemXmlApplicationContext(」beans.xml「);」「時,eclips不知道我應該導入什麼內容當我自己編寫「import org.springframework.context.ApplicationContext」時,它是強調的。
我應該怎麼做導入的ApplicationContext與最新版本的依賴?
編輯: 這是錯誤:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
ApplicationContext cannot be resolved to a type
FileSystemXmlApplicationContext cannot be resolved to a type
at com.caveofprogramming.spring.test.App.main(App.java:10)
,這是我的POM文件:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.caveofprogramming.spring.test</groupId>
<artifactId>spring-tutorial-5</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>4.3.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.3.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.3.3.RELEASE</version>
</dependency>
</dependencies>
</project>
編輯2:我也看到,程序接受4.1.1.RELEASE版本。 Mabye最新版本的依賴關係不是必需的嗎?我剛從Spring開始,每個人都說我應該使用最新版本。
編輯3;
,我發現使用彈簧背景下4.1.1.RELEASE
提供您所使用的確切的pom.xml。還要詳細描述問題,「導入不起作用」不夠具體。 – kryger