【问题标题】:Could not find method springBoot() for arguments - Spring Boot using Kotlin找不到参数的方法 springBoot() - 使用 Kotlin 的 Spring Boot
【发布时间】:2017-03-31 06:13:46
【问题描述】:

我尝试使用 Kotlin 创建第一个 Spring Boot 应用程序。所以,也许我犯了一些明显的错误或类似的错误。

我的 gradle.build 是:

buildscript {
    ext.kotlin_version = '1.0.5-2'
    ext.spring_boot_version = '1.4.2.RELEASE'
    repositories {
        jcenter()
    }
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "org.springframework.boot:spring-boot-gradle-plugin:$spring_boot_version"
    }
}

apply plugin: 'idea'
apply plugin: 'kotlin'
apply plugin: 'application'

jar {
    baseName = 'rest-voter'
    version = '0.1.0'
}

springBoot {
    mainClass = 'ru.hixon.Application'
}

repositories {
    jcenter()
}

dependencies {
    compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    compile "org.springframework.boot:spring-boot-starter-web:1.4.2.RELEASE"
    testCompile 'junit:junit'
}

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

错误是:

C:\Users\Desktop\rest-voter>gradlew build

FAILURE: Build failed with an exception.

* Where:
Build file 'C:\Users\Desktop\rest-voter\build.gradle' line: 22

* What went wrong:
A problem occurred evaluating root project 'rest-voter'.
> Could not find method springBoot() for arguments [build_3594if1jtm90vgb7v8evp206i$_run_closure2@459003a0] on root project 'rest-voter'.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 12.351 secs

我的主课是:

package ru.hixon

import org.springframework.boot.SpringApplication
import org.springframework.boot.autoconfigure.SpringBootApplication

@SpringBootApplication
open class Application {

}

fun main(args: Array<String>) {
    SpringApplication.run(Application::class.java, *args)
}

here 是我的应用程序的完整代码。

【问题讨论】:

    标签: spring gradle spring-boot kotlin


    【解决方案1】:

    你需要:

    apply plugin: 'spring-boot'
    

    还有:)

    只导入依赖是不够的。

    【讨论】:

    • 太奇怪了。我创建了包含这个插件的项目。然后gradle说,这个插件已经弃用了,我得用org.springframework.boot:spring-boot-gradle-plugin。然后我删除了它。现在我添加了这个插件,并没有关于弃用的消息
    • 对于新的 spring boot 版本,您需要使用 apply plugin: 'org.springframework.boot' 然后在其下方添加 buildInfo() 块以避免构建错误。
    猜你喜欢
    • 2018-10-01
    • 1970-01-01
    • 2021-09-13
    • 2021-06-09
    • 1970-01-01
    • 2020-09-19
    • 2022-09-23
    • 2018-09-12
    • 2020-07-08
    相关资源
    最近更新 更多