I am unable to launch my spring boot kotlin app, due to the following:
org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: @Configuration class 'TestApplication' may not be final. Remove the final modifier to continue.
I know that @configuration and @bean classes cannot be final so I add the allopen plugin in my pom file:
<build>
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
<testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<configuration>
<args>
<arg>-Xjsr305=strict</arg>
</args>
<compilerPlugins>
<plugin>spring</plugin>
</compilerPlugins>
</configuration>
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-allopen</artifactId>
<version>${kotlin.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
If I package my application and run it (java -jar) it works, but when I try to launch it from STS it won't work.
Kotlin version: 1.2.71 Kotlin eclipse plugin: 0.8.13 STS: 3.9.5
A class annotated with @Configuration cannot be final because Spring will use CGLIB to create a proxy for @Configuration class. CGLIB creates subclass for each class that is supposed to be proxied, however since the final class cannot have subclass CGLIB will fail.
Spring @Configuration annotation is part of the spring core framework. Spring Configuration annotation indicates that the class has @Bean definition methods. So Spring container can process the class and generate Spring Beans to be used in the application.
Yes, you are right.
This Question Can be Duplicate of :
IntelliJ Idea 2017.3 unable to start Kotlin Spring Boot App - @Configuration class may not be final
or
Used kotlin-spring plugin, still getting class not open error
. Anyways , I Just found Solution
You Just need to add open modifier to TestApplication kotlin class
@SpringBootApplication
open class TestApplication
might Solve your Issue .
I had the same problem. You must configure the Kotlin
plugin under Preferences > Kotlin > Compiler
and enable Compiler plugins
spring.
Kotlin Compiler Configuration Dialog
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With