【发布时间】:2017-12-20 15:40:05
【问题描述】:
试着按照这里的指南https://spring.io/guides/gs/rest-service/#scratch
这是我的 Gradle 文件
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 选项卡(应该在窗口的右侧)并刷新您的依赖项。
-
我没有看到 Gradle 选项卡
-
没关系,查看 -> 工具窗口 -> Gradle 为我提供了窗口,点击刷新。似乎现在可以工作了!谢谢!每次更改我的gradle时我都必须这样做吗?在 Android Studio 中我习惯于 Build 处理所有事情,我猜这里不一样?
标签: java spring intellij-idea gradle import