【问题标题】:Unable to Build Spring RestService Tutorial in IntelliJ无法在 IntelliJ 中构建 Spring RestService 教程
【发布时间】:2016-11-06 16:35:00
【问题描述】:

我正在尝试使用 Gradle 和 IntelliJ 完成 Spring Framework Restful Web 服务创建教程 (https://spring.io/guides/gs/rest-service/#scratch)。我已经严格遵守了所有内容,但对于 Spring、IntelliJ 和 Java 来说还是很陌生的,我不确定如何进一步调试我的问题。

当我尝试构建我的项目时,我收到一些错误,指出“Java:包 org.springframework.web.bind.annotation 不存在。”我猜我缺少库参考,但不确定如何检查和包含它。

buildscript {
    ext {
        springBootVersion = '1.3.5.RELEASE'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
        classpath("org.springframework:spring-web:${springBootVersion}")
    }
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot' 

jar {
    baseName = 'hello_springtest'
    version = '0.0.1-SNAPSHOT'
}

repositories {
    mavenCentral()
}

sourceCompatibility = 1.8
targetCompatibility = 1.8

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

task wrapper(type: Wrapper) {
    gradleVersion = '2.3'
}

eclipse {
    classpath {
        containers.remove('org.eclipse.jdt.launching.JRE_CONTAINER')
        containers     'org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8'
    }
}

只是想我会添加一些额外的信息。我仍然看到错误并且不确定原因,但我的项目确实报告构建成功。但是,当我尝试制作项目时,我收到注释不存在错误。

【问题讨论】:

  • 您还遵循了 IntelliJ 和 Gradle spring.io/guides/gs/intellij-idea 的 IDE 步骤?
  • @judoole 这看起来像是将教程从 Spring 导入 IntelliJ 的演练。我试图自己从头开始构建它,所以这些似乎都不适用。
  • 链接中的演练是针对这个确切的教程参考 spring.io/guides/gs/rest-service/#use-sts 我问的原因是这个错误看起来像是 IntelliJ 没有从 build.gradle 正确导入项目的错误

标签: java spring intellij-idea gradle spring-boot


【解决方案1】:

您的构建脚本中有一些依赖项,这在我看来是多余的,并导致 Gradle 查找其他依赖项。

只需从您的 buildscript 依赖项中删除此依赖项

classpath("org.springframework:spring-web:${springBootVersion}")

我认为没有理由在您的构建脚本中使用它。

【讨论】:

  • @Stansilav 你可能是对的,这只是我试图找到我所缺少的东西。我已经删除了该行,但不幸的是,当我运行我的 Project make 时,我仍然遇到相同的构建错误。
  • 这很奇怪,因为spring-boot-starter-web 依赖于spring-web,其中指定了包org.springframework.web.bind.annotation。可能您必须更新您的项目,因为尚未下载所有依赖项?或使用--refresh-dependencies 标志运行它
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-02-16
  • 2014-05-08
  • 1970-01-01
  • 2013-08-12
相关资源
最近更新 更多