Quarkus: Spring DI - @Autowired annotation does not work for setters

Created on 25 Feb 2020  路  6Comments  路  Source: quarkusio/quarkus

Describe the bug
When you put @Autowired annotation of the setter method the injection is not happened. As a result NPE is thrown.

To Reproduce

mvn verify -Dtest=org.otaibe.quarkus.jpa.tests.web.controller.LocationsControllerTest#testDestinationEndpoint
arespring kinbug

All 6 comments

/cc @geoand

Interesting, thanks!

@mkouba @manovotn does @Inject work on setters for CDI beans?

Yes, it should work. In fact, in CDI this kind of injection is called "initializers" and multiple injected params are supported. I did a quick search and there is a test for private setter: https://github.com/quarkusio/quarkus/blob/master/independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/injection/privateinitializer/PrivateInitializerInjectionTest.java#L33-L36.

@geoand how do you implement @Autowired? Is there an annotation trasnformer that perform the replacement @Autowired -> @Inject?

Yeah, I just saw it's my bad @mkouba :)

I have only implemented the transformation for fields, not methods :man_facepalming:

I'll send a PR for this later on tonight

Had a few minutes before heading out to the gym, so I opened #7421 :)

Was this page helpful?
0 / 5 - 0 ratings