无法在IntelliJ中构建Spring RestService教程

时间:2016-07-04 23:17:34

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

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

当我尝试构建我的项目时,我收到一些错误,声明" Java:package 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'
    }
}

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

1 个答案:

答案 0 :(得分:0)

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

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

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

我认为没有理由在你的buildcript中使用它。