You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring Boot Kotlin 1.7.20 K2编译器Spring插件失效求助

在Spring Boot Kotlin应用中使用K2编译器遇到Spring插件失效问题

我尝试在Spring Boot应用中使用Kotlin K2编译器,但发现Spring Kotlin插件似乎无法正常工作,或是我的配置存在问题。根据Kotlin官方说明,all-open和no-arg插件已支持K2,但整合了这两者的Spring Kotlin插件却不兼容?

我的build.gradle.kts配置如下:

plugins {
    id("org.springframework.boot") version "2.7.4"
    id("io.spring.dependency-management") version "1.0.14.RELEASE"
    kotlin("jvm") version "1.7.20"
    kotlin("plugin.spring") version "1.7.20"
}

启用K2编译器的配置为:

tasks.withType<KotlinCompile> {
    kotlinOptions {
        freeCompilerArgs = listOf("-Xuse-k2")
        jvmTarget = "17"
    }
}

启动应用时出现如下堆栈错误:

org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: @Configuration class 'MyConfigurationClass' may not be final. Remove the final modifier to continue.
Offending resource: class path resource [com/my/path/MyConfigurationClass.class]
    at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:72) ~[spring-beans-5.3.23.jar:5.3.23]
    at org.springframework.context.annotation.ConfigurationClass.validate(ConfigurationClass.java:217) ~[spring-context-5.3.23.jar:5.3.23]
    at org.springframework.context.annotation.ConfigurationClassParser.validate(ConfigurationClassParser.java:215) ~[spring-context-5.3.23.jar:5.3.23]
    at org.springframework.context.annotation ..

该错误表明all-open插件未生效。请问有成功在Kotlin Spring Boot应用中使用K2编译器的开发者能提供帮助吗?


内容的提问来源于stack exchange,提问作者J. Hegg

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.16 22:15:36