試圖按照這裏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));
}
}
打開Gradle選項卡(應位於窗口的右側)並刷新您的依賴關係。 – Tom
我沒有看到Gradle標籤 – user8313046
Nevermind,查看 - >工具窗口 - > Gradle讓我看到窗口,點擊刷新。似乎現在工作!謝謝!每次我改變我的Gradle時,我都必須這樣做嗎?在Android Studio中,我習慣於構建照顧所有的東西,我猜這有點不同嗎? – user8313046