Kotlin/kotlin-examples

Intellij spring boot restful compile error

syeutyu opened this issue ยท 14 comments

org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: @configuration class 'Application' may not be final. Remove the final modifier to continue.

I have a similar issues with the "may not be final":
Configuration problem: @configuration class 'DemoRestApplication' may not be final. Remove the final modifier to continue.
Offending resource: com.sample.demorest.DemoRestApplication

it's a bug on the intellij kotlin plugin, just add the open modifier to the class as a workaround and wait for the fix.

If this is indeed a bug in intellij alone, is there a ticket that tracks it?

Change the declaration from

class DemoRestApplication to open class DemoRestApplication

Similar behavior is for methods annotated as @bean
org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: @Bean method 'passwordEncoder' must not be private or final; change the method's modifiers to continue

Try using the plugin "org.jetbrains.kotlin:kotlin-allopen"

yole commented

The project configuration already applies the kotlin-spring plugin. There is no need to apply the open modifier to the class manually. The kotlin-spring plugin is also fully supported for builds in IntelliJ IDEA. If you experience problems with compilation, please make sure that you're using the latest version of the Kotlin plugin (1.3.10 as of this writing) and that you've run the project synchronization with Gradle. If the project still does not compile, please file a YouTrack issue and specify the versions of IntelliJ IDEA and the Kotlin plugin that you're using.

problem still exist. I use kotlin plugin latest version. I run application using "main" function. Not as gradle task "bootRun", but directly from application main function, cause its only way I know how to run spring with kotlin and devtools autoreload.

I am also having his problem. This used to work flawlessly and is now quite busted

Or you can use

@SpringBootApplication
open class DemoApplication {

    companion object{
        @JvmStatic
        fun main(args: Array<String>) {
            SpringApplication.run(DemoApplication::class.java, *args)
        }
    }
}

The need to make all spring @configuration classes in Intellij for a kotlin project is still there.
I'm using version 213-1.6.10-release-961-IJ6777.52 of the kotlin plugin and version 1.5 of kotlin.

Same here

Kotlin plugin: 213-1.6.21-release-334-IJ6777.52
Kotlin version: 1.6.21

Or you can use

@SpringBootApplication
open class DemoApplication {

    companion object{
        @JvmStatic
        fun main(args: Array<String>) {
            SpringApplication.run(DemoApplication::class.java, *args)
        }
    }
}

I am using scala language then open can't be used so any solution for this? @EvgenyPuch