Closed andrewcanby-finocomp closed 1 year ago
Is injecting Spring beans into Micronaut beans supported?
Hi @jeffbrown, that's the question isn't it?
The Grails 4.0.0 release notes mention:
Micronaut is now the parent application context of Grails thus allowing using many Micronaut features including the Micronaut HTTP Client and Kafka Client.
Perhaps I'm using it incorrectly, or doing something that is unsupported - I don't know. I can't find a definitive guide for Micronaut integration, other than using the features in isolation.
What is the suggested approach for using Grails services in a situation like the one described above?
I believe it is NOT possible right now to inject Grails/Spring Bean into Micronaut context. I think the only option is to craete a Micronaut Bean or you could experiment something like Micronaut for Spring (Micronaut for Spring allows you to use traditional Spring annotations which are mapped to Micronaut annotations at compilation time.)
Expected Behavior
Ability to use existing
grails-app/services
in a Micronaut@KafkaListener
s.Actual Behaviour
When trying to introduce a
@KafkaListener
to an existing Grails application, dependency injection fails.(full code in linked project)
The bean is seemingly available in both Micronaut and Grails/Spring contexts, albeit with slightly different resolution strategies. I expect this is somehow related to there being two contexts, but I am unable to determine what else should be done to make this work.
Steps To Reproduce
(In the linked project)
./gradlew bootRun
the project, note the startup failure@Singleton
to thegrails-app/services
the application "works".SpringSecurityService
) would interact in this scenarioEnvironment Information
(Not specific to this combination, just what I use)
Example Application
https://github.com/andrewcanby-finocomp/grails-micronaut-kafka-client-issue
Version
5.2.5