I was able to launch a Spring Boot Kotlin App from IntelliJ 2017.3. After the last IntelliJ fix update I cannot start that application from the IDE, getting this exception:<
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.
If you need to have open behavior default to all Spring related classes in kotlin, you can use
kotlin-allopen
plugin from here
https://search.maven.org/classic/#search%7Cga%7C1%7Ckotlin%20allopen
More info : https://www.baeldung.com/kotlin-allopen-spring
If plugin update does not help, check if version of kotlin in gradle matches ide's kotlin version.