IntelliJ Idea 2017.3 unable to start Kotlin Spring Boot App - @Configuration class may not be final
First of all, it's all due to class Kotlin class definition:
The
open
annotation on a class is the opposite of Java'sfinal
: it allows others to inherit from this class. By default, all classes in Kotlin are final
so if you are free to modify your source code, you can make your class not final, just adding open
to it's signature as follows:
@SpringBootApplication
open class DemoApplication
fun main(args: Array<String>) {
SpringApplication.run(DemoApplication::class.java, *args)
}
or one of the possible solutions, according to this article:
The
@SpringBootApplication
is a convenience annotation that marks the class with the@Configuration
,@EnableAutoConfiguration
and@ComponentScan
annotations. It is the@Configuration
annotation that forces the use of the open keyword.
Is to try to remove the @SpringBootApplication
annotation and annotate your class with @EnableAutoConfiguration
and @ComponentScan
to solve this issue.
Fixed upgrading IntelliJ's Kotlin pluging to 1.2.21: https://plugins.jetbrains.com/plugin/6954-kotlin/update/42501
If you get this error on IntelliJ, even with kotlin-spring plugin, you may want to check if the annotation processing has been enabled in IntelliJ.