Help us understand the problem. What is going on with this article?

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

More than 1 year has passed since last update.

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のサイトを見てもらうと詳しい

http://engineering.pivotal.io/post/spring-boot-application-with-kotlin/

内容としては @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 などの修正は必要なかった

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away