openrewrite / openrewrite/rewrite-spring
Replacing field injection with constructor injection
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 403
- Forks
- 149
- Avg merge
- 2h 33m
- Merged PRs (30d)
- 10
Description
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
class A {
@Autowired
@Qualifier("B")
private B b;
}
Describe the situation after applying the recipe
class A {
private B;
public A(@Qualifier("B") b) {
this.b = b;
}
}
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No file or test is named, so begin by reviewing the repository's existing Spring recipe entry points and unit-test conventions. Use the issue's before-and-after examples to define the initial transformation, then verify the stated constructor, annotation, qualifier, and caveat cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- backend, tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100