使用kotlin-spring插件,还是得不到类的打开错误
尽管添加了kotlin-spring插件,我正在获得一个不能最终决定的类,需要开放。 插件的全部目的是不为每个类手动添加open关键字。
请指导我让Kotling-Spring插件使用下面的代码。
的build.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" }
AppConfig.java
@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
有同样的问题。 在Intellij中启用注释处理解决了这个问题: