Open crankydillo opened 2 months ago
Hi @crankydillo ; Thanks for the offer to help! Agree that this would be a nice addition, and best to start with a limited set of known cases, and reject anything else (at first) that might make it more complicated.
On the known cases to reject I'd include
@Autowired
, like validation or jackson annotations
super()
What we're left with then is
Anything you'd add to this list?
RE field->constructor annotations, I was thinking we could move @Autowired
and @Autowired + @Qualifier
. I know for us that would handle quite a few cases.
I might still do large constructors or maybe make that part configurable. The idea is to create an obvious code smell, which is currently hidden by 'Spring magic'.
When is this coming? Quick fixes applied by this recipe would be very helpful in reducing the boilerplate.
hi @punkratz312 ; we don't have a fixed schedule, but you're welcome to push up a draft PR with tests if you'd like to help out. :)
Adding a note here that this is also necessary when you want to move away from @org.springframework.beans.factory.annotation.Required
, which was removed in Spring Framework 6+.
We have this as a quick fix in the Spring Tools for VSCod and Eclipse: https://x.com/springtools4/status/1843922035824787896
It uses org.openrewrite.java.spring.AutowiredFieldIntoConstructorParameterVisitor
from rewrite-spring
, so improvements to this (e.g. handling the @Qualifier
annotation nicely) should be made there, I think.
@crankydillo Interested in contributing some improvements to the org.openrewrite.java.spring.AutowiredFieldIntoConstructorParameterVisitor
, for example to cover @Qualifier
annotations in a nice way?
What problem are you trying to solve?
We want to convert a bunch of classes that used Spring field injection to constructor injection. We are willing to live with some caveats (e.g. only works if no constructors, select annotations, etc).
Describe the situation before applying the recipe
Describe the situation after applying the recipe
Any additional context
We could likely get value from something that didn't hit all the corner cases. However, if there are a bunch of corner cases that ultimately means an unending feature request on this, it's not like we really need this.
Are you interested in contributing this recipe to OpenRewrite?
Yes.