Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Tool Suite: @Configuration class may not be final. Remove the final modifier to continue

Tags:

eclipse

kotlin

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

like image 730
rena Avatar asked Feb 05 '19 21:02

rena


People also ask

Can a @configuration class be final?

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.

What is the use of @configuration in spring boot?

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.

Is @configuration mandatory?

Yes, you are right.


2 Answers

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 .

like image 174
Vamsi Krishna DS Avatar answered Sep 30 '22 16:09

Vamsi Krishna DS


I had the same problem. You must configure the Kotlin plugin under Preferences > Kotlin > Compiler and enable Compiler plugins spring.

Kotlin Compiler Configuration Dialog

like image 22
Andreas Gebhardt Avatar answered Sep 30 '22 17:09

Andreas Gebhardt