IntelliJ Idea 2017.3 unable to start Kotlin Spring Boot App - @Configuration class may not be final

后端 未结 5 639
悲&欢浪女
悲&欢浪女 2021-01-03 23:52

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:<

5条回答
  •  说谎
    说谎 (楼主)
    2021-01-04 00:16

    First of all, it's all due to class Kotlin class definition:

    The open annotation on a class is the opposite of Java's final: 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) {
        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.

提交回复
热议问题