【问题标题】:import org.springframework.web cannot be resolved (gradle)导入 org.springframework.web 无法解析(gradle)
【发布时间】:2018-02-13 14:59:44
【问题描述】:

import org.springframework.web 无法解析发生在以下几行:

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

@RestController
[...]
@RequestMapping("/")
[...]


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

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

dependencies {
compile('org.springframework.boot:spring-boot-starter')
testCompile('org.springframework.boot:spring-boot-starter-test')
}

【问题讨论】:

  • 如果你想做 Web 开发,spring-boot-starter-web 怎么样..

标签: java spring spring-boot gradle


【解决方案1】:

您需要添加 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")
  • 我只想在您的答案中添加一个深入的评论。如果你想制作一个 spring boot web starter 应用程序,你需要点击 war 选项作为包装样式。这将自动添加您在 spring boot initializer [link] (start.spring.io) 中提到的代码
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-07-21
  • 2019-05-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多