If you're still struggling with some issues while building Spring Boot applications, here are some pro-tips to help you build faster and better Spring Boot+Kotlin applications.
By default, classes and the functions in Kotlin are final. In order to make a particular class or function non-final you need to use the open
keyword. It is one of the pain points of using Kotlin with Spring as the classes for external configuration properties (Spring beans proxified with CGLIB like @Configuration
classes) are required to be open
.
Fortunately, with Kotlin v1.0.6, there is a Kotlin-Spring plugin that tells the compiler to open
classes and their member functions for classes annotated or meta-annotated with one of the following annotations:
@Component
@Async
@Transactional
@Cacheable
- Also, classes annotated with
@Configuration
,@Controller
,@RestController
,@Service
, or@Repository
are automatically opened since these annotations are meta-annotated with@Component
In a nutshell...