【问题标题】:Spring Tool Suite: @Configuration class may not be final. Remove the final modifier to continueSpring Tool Suite:@Configuration 类可能不是最终的。删除 final 修饰符以继续
【发布时间】:2019-06-29 18:56:05
【问题描述】:

由于以下原因,我无法启动我的 spring boot kotlin 应用程序:

org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: @Configuration class 'TestApplication' may not be final. Remove the final modifier to continue.

我知道 @configuration 和 @bean 类不能是最终的,所以我在我的 pom 文件中添加了 allopen 插件:

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

如果我打包我的应用程序并运行它(java -jar)它可以工作,但是当我尝试从 STS 启动它时它不会工作。

Kotlin 版本:1.2.71 Kotlin eclipse 插件:0.8.13 STS:3.9.5

【问题讨论】:

    标签: eclipse kotlin


    【解决方案1】:

    这个问题可以重复:

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

    Used kotlin-spring plugin, still getting class not open error

    。 无论如何,我刚刚找到了解决方案

    您只需要在 TestApplication kotlin 类中添加 open 修饰符

    @SpringBootApplication
    open class TestApplication 
    

    可能会解决您的问题。

    【讨论】:

    • 如果您说它可能是重复的,请改为标记帖子。
    • 以上问题相似,所以没有标记
    • 将 open 修饰符也添加到方法中。
    • 这不是 kotlin-maven-allopen 的用途吗?
    【解决方案2】:

    我遇到了同样的问题。必须在Preferences &gt; Kotlin &gt; Compiler下配置Kotlin插件并启用Compiler pluginsspring。

    Kotlin Compiler Configuration Dialog

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-06
      • 2015-05-14
      • 1970-01-01
      • 2019-08-10
      • 2021-07-30
      • 1970-01-01
      相关资源
      最近更新 更多