Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace @Required on setters with @Autowired #612

Merged
merged 12 commits into from
Oct 29, 2024

Conversation

nielsdebruin
Copy link
Contributor

@nielsdebruin nielsdebruin commented Oct 28, 2024

What's changed?

The deprecated @Required annotation can be applied to setters of field, to ensure a bean is injected. However, the annotation is now deprecated. This recipe will replace the @Required annotation with @Autowired.

Anything in particular you'd like reviewers to focus on?

Anyone you would like to review specifically?

@timtebeek @Laurens-W

Checklist

  • I've added unit tests to cover both positive and negative cases
  • I've read and applied the recipe conventions and best practices
  • I've used the IntelliJ IDEA auto-formatter on affected files

@nielsdebruin nielsdebruin self-assigned this Oct 28, 2024
@nielsdebruin nielsdebruin added the recipe Recipe requested label Oct 28, 2024
nielsdebruin and others added 9 commits October 28, 2024 14:09
…structorParameter.java

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
…quiredFieldIntoConstructorParameterTest.java

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
…quiredFieldIntoConstructorParameterTest.java

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
…quiredFieldIntoConstructorParameterTest.java

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@nielsdebruin nielsdebruin force-pushed the recipe/required-field branch from 61138ae to 55cfa44 Compare October 29, 2024 11:23
@nielsdebruin nielsdebruin changed the title @Required setters to constructor initial test only Replace @Required on setters with @Autowired Oct 29, 2024

import java.util.Comparator;

public class ReplaceRequiredAnnotationOnSetterWithAutowired extends Recipe {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of a recipe would this also be possible with a declarative recipe ChangeType? Or are there edge cases that won't cover?

Whenever possible try to do declaratively what we can; that helps reduce what we need to maintain going forward.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good suggestion, Thanks!

@nielsdebruin nielsdebruin marked this pull request as ready for review October 29, 2024 11:47
@nielsdebruin nielsdebruin marked this pull request as draft October 29, 2024 11:50
Copy link
Contributor

@timtebeek timtebeek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also: your recipe is not yet hooked into any of the Spring Boot migrations, meaning folks would have to run this one manually; please hook it into the appropriate place in a larger migration.

@nielsdebruin nielsdebruin marked this pull request as ready for review October 29, 2024 14:07
@Laurens-W Laurens-W merged commit b0a95c8 into openrewrite:main Oct 29, 2024
2 checks passed
@nielsdebruin nielsdebruin deleted the recipe/required-field branch October 29, 2024 14:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
recipe Recipe requested
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants