Spring and Kotlin final classes
It’s time for the next topic in the series of blogs on using Spring Framework with Kotlin support in IntelliJ IDEA.
Kotlin classes are final by default, but some Spring functionality requires classes to be open. For instance,
@Configuration classes should be extendable, and methods annotated with
@Async must also be extendable. If you don’t want to bother with it, there is the all-open plugin as well as the spring plugin for Kotlin compiler. But if you don’t like the idea of modifying Kotlin rules by compiler plugins and don’t mind an additional
open modifier on your classes and methods, then IntelliJ IDEA offers an inspection that checks that all necessary classes and members are declared open:
Ordinary beans in Spring don’t have to be
open, unless they have methods with specific annotations, like
So if you don’t use Kotlin compiler plugins, IntelliJ IDEA will still check the openness of your classes and members to avoid problems at runtime.
More posts about Kotlin with Spring support in IntelliJ IDEA are to come. Please stay tuned!