I try to implement method injection using Spring 5.1.6 and Kotlin 1.3.20
When i implement method injection using Kotlin method getNotification isn't return new object of SchoolNotification. I get Kotlin NPE.
@Component
@Scope("prototype")
open class SchoolNotification {
override fun toString(): String {
return Objects.toString(this)
}
}
StudentServices:
@Component
open class StudentServices {
@Lookup
fun getNotification(): SchoolNotification {
return null!!
}
}
Everything is ok when i write the same code with Java
@Component
@Scope("prototype")
public class SchoolNotification {
}
StudentServices:
@Component
public class StudentServices {
@Lookup
public SchoolNotification getNotification() {
return null;
}
}
Main
fun main() {
val ctx = AnnotationConfigApplicationContext(ReplacingLookupConfig::class.java)
val bean = ctx.getBean(StudentServices::class.java)
println(bean.getNotification())
println(bean.getNotification())
ctx.close()
}
What am i doing wrong using Kotlin?