I'm trying to lazily initialize a bean in a spring boot app with Kotlin.
I have a spring @Configuration file where i have a lazily annotated bean:
@Lazy
@Bean
open fun createSomething(): Something {
return Something("yo")
}
I have a rest controller where i have lazily autowired the bean
@Lazy
@Autowired
private lateinit var something: Something
I'm accessing a variable in the class in one of the @RequestMappings
println(something.thing)
I've added logs in the @Bean method and confirmed that the bean isn't getting eagerly initialized. The problem is the it's not getting initialized even on access. The class is a simple open class.
open class Something(val thing: String)
The bean initialization never happens. I don't know what i'm doing wrong.
Here are the versions:
Java: 1.8.0_191
Kotlin: 1.1.60
Spring Boot: 2.0.2.RELEASE
I don't know if it's some sort of version problem or i'm doing something in using the lazy bean. Appreciate the help.