2017-07-15 82 views
0

試圖按照這裏https://spring.io/guides/gs/rest-service/#scratch爲什麼我的IntelliJ IDEA項目找不到這個導入?

蒞臨指導是我的搖籃文件

version '1.0' 

buildscript { 
    repositories { 
     mavenCentral() 
    } 
    dependencies { 
     classpath("org.springframework.boot:spring-boot-gradle-plugin:1.5.3.RELEASE") 
    } 
} 

apply plugin: 'java' 
apply plugin: 'eclipse' 
apply plugin: 'idea' 
apply plugin: 'org.springframework.boot' 

jar { 
    baseName = 'gs-rest-service' 
    version = '0.1.0' 
} 

repositories { 
    mavenCentral() 
} 

sourceCompatibility = 1.8 
targetCompatibility = 1.8 

dependencies { 
    testCompile group: 'junit', name: 'junit', version: '4.11' 
    compile("org.springframework.boot:spring-boot-starter-web") 
    testCompile('org.springframework.boot:spring-boot-starter-test') 
    testCompile('com.jayway.jsonpath:json-path') 
} 

和公正的情況下,我的項目的屏幕:

https://i.stack.imgur.com/m8aqE.png

出於某種原因,當我點擊生成,它似乎工作正常,但無論出於何種原因,它無法找到org.springframework文件,如該文件中的導入:

package hello; 

import java.util.concurrent.atomic.AtomicLong; 
import org.springframework.web.bind.annotation.RequestMapping; 
import org.springframework.web.bind.annotation.RequestParam; 
import org.springframework.web.bind.annotation.RestController; 

@RestController 
public class GreetingController { 

    private static final String template = "Hello, %s!"; 
    private final AtomicLong counter = new AtomicLong(); 

    @RequestMapping("/greeting") 
    public Greeting greeting(@RequestParam(value="name", defaultValue="World") String name) { 
     return new Greeting(counter.incrementAndGet(), 
       String.format(template, name)); 
    } 
} 
+0

打開Gradle選項卡(應位於窗口的右側)並刷新您的依賴關係。 – Tom

+0

我沒有看到Gradle標籤 – user8313046

+0

Nevermind,查看 - >工具窗口 - > Gradle讓我看到窗口,點擊刷新。似乎現在工作!謝謝!每次我改變我的Gradle時,我都必須這樣做嗎?在Android Studio中,我習慣於構建照顧所有的東西,我猜這有點不同嗎? – user8313046

回答

2

您是否在IDEA中刷新了Gradle項目?

enter image description here

當你這樣做,你應該能夠看到「外部庫」列表中的所有需要​​的依賴。

enter image description here

編輯:由於某種原因,你的想法可能沒有搖籃正確配置。您可以在文件檢查 - >設置... - >構建,執行,部署 - >生成工具 - >搖籃如果你的項目與搖籃正確鏈接:

enter image description here

如果您想讓Gradle自動導入所有依賴關係,您可以標記爲「使用自動導入」。唯一的問題是,它可能會消耗大量資源並使IDE運行緩慢。這聽起來可能不是一個方便的解決方案,但在需要時手動刷新項目效果會更好。

我希望它有幫助。

+0

我的正確嗎? http://i.imgur.com/zJszOsz.png – user8313046

+0

是的,看起來很好看 –

+0

更改依賴關係時是使用gradle工具欄刷新窗口還是大多數人使用它類似於我使用Android Studio的方式? (點擊構建和其他一切似乎工作/導入/等) – user8313046

相關問題