使用过的kotlin-spring插件,仍然出现类未打开错误 [英] Used kotlin-spring plugin, still getting class not open error

查看:45
本文介绍了使用过的kotlin-spring插件,仍然出现类未打开错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尽管添加了kotlin-spring插件,但我得到的类不能是最终的,需要打开.插件的全部目的是不手动将open关键字添加到每个类.

I am getting a class cannot be final, needs to be open, despite adding the kotlin-spring plugin. The whole purpose of the plugin is to not manually add the open keyword to every class.

请指导我让Kotling-Spring插件与以下代码配合使用.

Please guide me on getting the Kotling-Spring plugin to work with code below.

build.gradle

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

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中启用注释处理可以解决此问题:

Had the same problem. Enabling annotation processing in Intellij solved the issue:

这篇关于使用过的kotlin-spring插件,仍然出现类未打开错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆