2015-05-13 79 views
3

我從網上下載http://maven.springframework.org/release/org/springframework/spring/java的春天導入錯誤

彈簧框架,然後4.1.6.RELEASE我跟着春天網站http://spring.io/guides/gs/rest-service/啓動一個項目,但我發現在它裏面有問題。

//The import org.springframework.boot cannot be resolved 
import org.springframework.boot.SpringApplication; 
import org.springframework.boot.autoconfigure.SpringBootApplication; 

它似乎無法找到jar文件,所以無法導入它,但我已經添加了所有jar文件來構建路徑。
我該如何解決? Spring和SpringFramework是同一個嗎?

+0

您是否在IDE中添加了JAR作爲依賴項?你在用什麼IDE? – JonasCz

+0

我已經添加了all.I使用eclipse。 – weaver

+1

不要尋找罐子手動使用像maven或gradle這樣的東西來爲你做。它會爲你節省很多時間和頭痛......當遵循這些指南時,總有兩種味道是Maven和Gradle。選擇其中任何一個,但請不要在這些日子裏尋找罐子...... –

回答

8

看起來你正在試圖訪問屬於Spring Boot項目的類,它可能是你的Spring庫不包含與Spring Boot項目相關的庫。

當然我建議你通過Maven的或搖籃導入由Spring Boot Quickstart.

的建議,但如果你想目前手動添加,最新發布的罐子SpringApplication是彈簧啓動1.2。 3.RELEASE.jar

搜尋HERE

而且SpringBootApplication類內發現的彈簧啓動自動配置,1.2.3.RELEASE.jar

搜尋HERE

因此,檢查您的當前版本中是否有類似的jar,如果沒有,請下載它們,也請記住,因爲您正在手動處理依賴關係,所以很可能這兩個新庫依賴於它們自己,也必須適應他們。

+1

非常感謝你!有用! – weaver

+0

嗨。我已經在STS中用maven下載了,但我仍然無法在類上添加@SpringBootApplication。請幫幫我。 – Abdul

+0

\t \t org.springframework.boot \t \t 彈簧引導起動父 \t \t 1.4.2.RELEASE \t \t \t <依賴性> \t \t \t \t \t org.springframework.boot \t \t \t 彈簧引導起動的web \t \t \t。這是我的pom.xml – Abdul

1

Spring framework zip你從maven回購下載的神器沒有Spring boot罐子,這就是爲什麼它不編譯。 下載彈簧啓動jar並將其添加到您的類路徑中。

此鏈接定義了maven依賴項。

http://projects.spring.io/spring-boot/

3

我有問題,只是在包裝org.springframework.boot.autoconfigure任何事情。雖然適當的罐子被列入的classpath *無法解析/編譯。

我的解決方法:擦拭本地Maven倉庫

運行命令行「MVN乾淨編譯」給我看像

[ERROR] error reading /Users/greyshine/.m2/repository/org/springframework/boot/spring-boot-autoconfigure/1.4.3.RELEASE/spring-boot-autoconfigure-1.4.3.RELEASE.jar; invalid LOC header (bad signature) 

這給了我的猜測,製造品是不是在正常下載線第一次運行。 我使用'mvn clean compile'重建了我的maven spring boot repository artefacts(即位於〜/ Users/MYHOME/.m2/repository/org/springframework/boot),然後它全部運行。

0

我有一個類似的問題,並通過調整pom來修復它。XML

<dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter</artifactId> 
    </dependency> 

到:

<dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-web</artifactId> 
    </dependency> 
-1

作爲替代切除整個本地Maven回購的德克·舒馬赫的方法,我只是去掉.m2目錄/庫/組織/ springframework的文件夾強制該部分重新下載。