Using kotlin-spring plugin still getting class not open error

I am getting the class cannot be final, must be open despite adding the kotlin-spring plugin. The main goal of the plugin is not to manually add the open keyword to each class.

Please explain to me how to get the Kotling-Spring plugin to work with the code below.

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()
    }
}

      

Mistake:

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

+5


source to share


3 answers


There was the same problem. Enabling annotation processing in Intellij solved the problem:



enter image description here

+1


source


There was a similar problem. Failed to start from IDE but gradlew.bat build bootRun

worked. Solved by updating the Kotlin plugin in IDEA , from 1.2.40 to 1.2.41.



0


source


I also faced similar issue when starting my Springboot application. I finally found out that the default Kotlin Class is final. You need to add public before the class name

So, you need to change the class modifier as follows:

public class AppConfig {

Link:

http://engineering.pivotal.io/post/spring-boot-application-with-kotlin/

0


source







All Articles