Skip to content

Conversation

nurdy-kim
Copy link

What's changed?

I added a new ScanningRecipe - MigrateHooksToReactorContextProperty. This recipe automatically removes the Hooks.enableAutomaticContextPropagation() method call from main methods within @SpringBootApplication classes. After that it adds the new spring.reactor.context-propagation=true property to application.properties or application.yml files, which provides the same functionality.

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

I'm particularly concerned about whether the addSpringProperty method is working as expected. I'd appreciate it if you could pay close attention to that part during the review.

Anyone you would like to review specifically?

@nmck257, @timtebeek

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

@github-project-automation github-project-automation bot moved this to In Progress in OpenRewrite Aug 26, 2025
@nurdy-kim nurdy-kim marked this pull request as ready for review August 26, 2025 12:39

@Override
public AtomicBoolean getInitialValue(ExecutionContext ctx) {
return new AtomicBoolean(false);
Copy link
Member

Choose a reason for hiding this comment

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

While perhaps not as common in practice, we'd need to correctly handle multi module projects too, which might each have this hook and a configuration properties file, or multiple. You can look at this example for how to handle that with an alternative Accumulator:

@Data
static class JavaProjects {
Set<JavaProject> applicableProjects = new HashSet<>();
Set<JavaProject> processedProjects = new HashSet<>();
Map<JavaProject, Path> sourceToCommentByProject = new HashMap<>();
}

Copy link
Member

@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.

Great start here @nurdy-kim ! I've called out a potential source of issues with the AtomicBoolean you'd been using. That's an older pattern we're looking to phase out on new recipes. Could you make the necessary adjustments based on the example given?

@nurdy-kim
Copy link
Author

Thanks for the feedback! I'll make the necessary adjustments! :)

@timtebeek timtebeek marked this pull request as draft August 26, 2025 18:05
@timtebeek timtebeek added the recipe Recipe requested label Aug 26, 2025

import static org.openrewrite.Preconditions.and;

public class MigrateHooksToReactorContextProperty extends ScanningRecipe<AtomicBoolean> {
Copy link
Member

Choose a reason for hiding this comment

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

Also might be good to hook this recipe into one of the larger composites, or Spring Boot best practices, such that it's run automatically.

Copy link
Author

Choose a reason for hiding this comment

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

This recipe can be applicable from Spring Boot 3.2. I believe it would be a good fit for the Migrate to Spring Boot 3.2 recipe. If not, could you please provide some guidance on this?

Copy link
Member

Choose a reason for hiding this comment

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

That then makes sense, yes thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
recipe Recipe requested
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

2 participants