rewrite-spring
rewrite-spring copied to clipboard
SB 3.2 - Use Reactor Context-Propagation property
What problem are you trying to solve?
Use this shiny new property: https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-3.2-Release-Notes#properties
...as a replacement for calling Hooks.enableAutomaticContextPropagation();
before booting the app, as mentioned in this blog post: https://spring.io/blog/2023/03/30/context-propagation-with-project-reactor-3-unified-bridging-between-reactive#automatic-context-propagation
What precondition(s) should be checked before applying this recipe?
Probably UsesType
for Hooks
and SpringApplication
Describe the situation before applying the recipe
@SpringBootApplication
public class MyApp{
public static void main(final String[] args) {
Hooks.enableAutomaticContextPropagation();
SpringApplication.run(MyApp.class, args);
}
}
Describe the situation after applying the recipe
@SpringBootApplication
public class MyApp{
public static void main(final String[] args) {
SpringApplication.run(MyApp.class, args);
}
}
...combined with a spring property addition:
spring:
reactor:
context-propagation: auto
Have you considered any alternatives or workarounds?
Any additional context
Are you interested in contributing this recipe to OpenRewrite?
Maybe eventually; eager contributors are welcome to grab it first
Seems like a good first issue indeed ; we can have a JavaIsoVisitor return null
from visitMethodInvocation
when Hooks.enableAutomaticContextPropagation()
is found in a @SpringBootApplication
main
method. Then call doAfterVisit(new AddSpringProperty("spring.reactor.context-propagation", "true", null, null).getVisitor())
to add the property and done. Couple tests and we should be good. Anyone welcome to pick this up!
I think it might have to be a ScanningRecipe
, such that it can make the choice to adjust a property file while visiting a java file, but still feels within the realm of a first issue
Hello, My name is prem and I would like to work on this issue. Is it still active ?
Hi! Yes sure; if you open up a draft pull request with the tests I'll assign the issue to you.
We need to replace the use of Hooks.enableAutomaticContextPropagation()
with the spring.reactor.context-propagation property as a part of Spring Boot 3.2 ! I've been searching the entire project to locate the file or code snippet where Hooks.enableAutomaticContextPropagation()
is used, but I haven't been successful so far. Could you please provide some guidance on where I should be looking or any specific classes or configurations.
@Shiroo77
The original issue description shows what I believe to be the most common pattern: calling the Hooks...
method within main
before calling SpringApplication::run
. I'm not aware of any common patterns where the method would appear somewhere else; I suspect it may not work properly if applied late in the spring app lifecycle