Аннотации @Inject для службы, определенной с помощью «@ApplicationScope», не удается внедрить в Kotlin.
"kotlin.UninitializedPropertyAccessException: средство приветствия свойств lateinit не было инициализировано"
Объяснение аналогичного вопроса: «Эта проблема возникает как сочетание того, как Kotlin обрабатывает аннотации, и отсутствия @Target в определении аннотации .... Добавьте @field: xxx»
Вопрос в том, как мне заставить это работать для внедрения службы?
import com.amazonaws.services.lambda.runtime.Context
import com.amazonaws.services.lambda.runtime.RequestHandler
import javax.enterprise.context.ApplicationScoped
import javax.inject.Inject
class HelloRequest() {
var firstName: String? = null
var lastName: String? = null
}
@ApplicationScoped
open class HelloGreeter() {
open fun greet(firstName: String?, lastName: String?): String {
return "$firstName, $lastName"
}
}
class HelloLambda : RequestHandler<HelloRequest, String> {
@Inject
lateinit var greeter: HelloGreeter
override fun handleRequest(request: HelloRequest, context: Context): String {
return greeter.greet(request.firstName, request.lastName)
}
}
Similar questions: "This problem results as a combination of how Kotlin handles annotations and the lack of the a @Target on the ... annotation definition. Add @field: xxx"