导入org.springframework.web无法解析(渐变)

5 java spring gradle spring-boot

在以下行上无法解决导入org.springframework.web的问题:

import org.springframework.web.bind.annotation.*;
[...]

@RestController
[...]
@RequestMapping("/")
[...]
Run Code Online (Sandbox Code Playgroud)


这发生在我的Spring Starter项目中。我正在使用Spring与Gradle 2.x

我经常读到您需要更改build.gradle文件中的依赖项,但我不知道在其中添加什么。我的依存关系如下所示:

dependencies {
compile('org.springframework.boot:spring-boot-starter')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
Run Code Online (Sandbox Code Playgroud)

vis*_*mar 8

您需要添加 compile("org.springframework.boot:spring-boot-starter-web")

检查这个https://spring.io/guides/gs/spring-boot/#scratch

  • 谢谢你!在最新的 Gradle 版本中,它是 `implementation("org.springframework.boot:spring-boot-starter-web")` (2认同)