【问题标题】:Spring Boot Kotlin Project Not Working In EclipseSpring Boot Kotlin 项目在 Eclipse 中不起作用
【发布时间】:2019-11-27 15:21:03
【问题描述】:

我有一个在eclipse中运行的spring boot项目,有以下版本

Spring Boot: 2.1.6.RELEASE
Kotlin:1.3.41

代码在 IntellIJ 中运行良好 - 但在 eclipse 中出现这些错误

org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: @Configuration class 'SwaggerConfig' may not be final. Remove the final modifier to continue.
Offending resource: class path resource [com/kotlin/springboot/kotlindemo/config/SwaggerConfig.class]

这里是 SwaggerConfig 类

@Configuration
@EnableSwagger2
class SwaggerConfig {

    @Bean
    fun api(): Docket = Docket(DocumentationType.SWAGGER_2)
    .select()
    .apis(Predicates.not(RequestHandlerSelectors.basePackage("org.springframework.boot")))
    .build()

}

我的 pom.xml 文件中有以下插件设置

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

再次,在 IntelliJ 中一切正常,但在 eclipse 中不行 有什么想法可以在eclipse中解决这个问题吗?

谢谢 达米安

【问题讨论】:

  • 您是否尝试从 SwaggerConfig 中删除 final 修饰符? :)
  • 它也不应该在 IntelliJ 中工作(看到错误消息)。 Spring 总是将所有使用@Configuration 注释的类或使用@Cacheable 等代码生成功能的类进行子类化。由于 Kotlin 默认将其类设为最终类,因此您必须明确地将它们设为 open class
  • @Bitman 类没有 final 修饰符。如果我添加 open 它可以工作,但我想使用 kotlin-maven-plugin
  • @roookee - kotlin-maven-plugin 有一个 compilerPlugin 部分,应该采用它。这就是它在 intelliJ 中工作的原因
  • @roookee - 这个链接更好地描述了插件的功能 - dzone.com/articles/open-your-classes-and-methods-in-kotlin

标签: spring eclipse spring-boot intellij-idea kotlin


【解决方案1】:

我升级到最新版本的 kotlin 插件,这解决了我面临的问题。

【讨论】:

    【解决方案2】:

    在 SwaggerConfig 类声明之前尝试 open Kotlin 修饰符:

    open class SwaggerConfig {...}
    

    【讨论】:

      猜你喜欢
      • 2017-07-04
      • 2019-01-27
      • 2020-11-15
      • 2017-08-26
      • 2019-03-27
      • 2020-11-22
      • 2022-01-09
      • 1970-01-01
      • 2017-12-22
      相关资源
      最近更新 更多