6
2

More than 5 years have passed since last update.

Kotlin+Spring Bootにて「@Configuration class may not be final」的なエラーが出たとき

Last updated at Posted at 2017-05-30

Kotlin+Spring Bootにて「@Configuration class may not be final」的なエラーが出たとき

この記事の対象フレームワークなど

  • kotlinVersion = '1.1.2'
  • springBootVersion = '2.0.0.M1'

起こった現象

Spring Bootを起動すると

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

みたいなエラーが出る。
当方では、kotlinでApplicationクラスを作成し、Java側でConfigurationクラスを作成している場合に発生した。

対応

詳細はPivotalのサイトを見てもらうと詳しい

内容としては @Configuration をつける対象は open指定して下さいよゴニョゴニョ.. というような感じでしょうか。

直接的な対応としてはApplicationクラスのアノテーションを

@SpringBootApplication → @EnableAutoConfiguration + @ComponentScan

に変更すればOKであった。

@EnableAutoConfiguration
@ComponentScan
@EnableDiscoveryClient
@EnableCircuitBreaker
class Application

fun main(args: Array<String>) {
    SpringApplication.run(Application::class.java, *args)
}

※ Pivotalの記事中にも注意書きされているが、今回利用したバージョンでは build.gradle などの修正は必要なかった

6
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
2