尽管添加了 kotlin-spring 插件,但我得到的类(class)不能是最终的,需要打开。该插件的全部目的是不手动将 open 关键字添加到每个类。
请指导我让 Kotling-Spring 插件与下面的代码一起工作。
构建.gradle
buildscript {
ext.kotlin_version = "1.1.2"
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.kotlin:kotlin-allopen:$kotlin_version"
classpath "org.jetbrains.kotlin:kotlin-noarg:$kotlin_version"
}
}
apply plugin: "kotlin"
apply plugin: "kotlin-spring"
apply plugin: "kotlin-noarg"
apply plugin: "idea"
repositories {
mavenCentral()
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version"
compile"org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
compile "org.springframework:spring-context:4.3.8.RELEASE"
testCompile "org.springframework:spring-test:4.3.8.RELEASE"
testCompile "junit:junit:4.11"
}
应用程序配置文件
@Configuration
class AppConfig {
@Bean
fun game(): Game {
return BaseballGame(redSox(),cubs())
}
@Bean
fun redSox(): Team {
return RedSox()
}
@Bean
fun cubs(): Team {
return Cubs()
}
}
错误:
Exception in thread "main" org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: @Configuration class 'AppConfig' may not be final. Remove the final modifier to continue.
Offending resource: AppConfig
REF: https://kotlinlang.org/docs/reference/using-gradle.html#plugin-and-versions
最佳答案
关于spring - 使用 kotlin-spring 插件,仍然得到 class not open 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44335371/