Reputation: 141
Code:
@Component
open class UserProjectionQuery {
@Autowired
private lateinit var repository: UserDocumentRepository
@Autowired
private lateinit var updateEmitter: QueryUpdateEmitter
@QueryHandler
fun handle(query: QueryUserIdForUsername): String? {
//stuff
}
@EventHandler
fun on(evt: UserAuthenticated) {
//stuff
}
}
Apparently it doesn't inject my repository nor update emitter.
The event handler creates AnnotationQueryHandlerAdapter
instead of AnnotationEventHandlerAdapter
.
The solution atm is to move out the @EventHandler
's to separate class and keep them there while @QueryHandler
's in separate class too.
I remember it was working with java. I'm not sure what i'm missing here but it seems like it's a spring-kotlin bug? Any tip would be appreciated, thanks
Upvotes: 0
Views: 768
Reputation: 661
This is weird. I'm sure that my example is working correctly with the similar use case
Consider using constructor to inject your dependencies (you will avoid var
and lateinit
)
class UserProjectionQuery(private val repository: UserDocumentRepository, private val updateEmitter: QueryUpdateEmitter)
You can also use maven plugin kotlin-maven-plugin
to open all Spring configuration classes: https://github.com/idugalic/digital-restaurant/blob/master/pom.xml#L177
Upvotes: 3