Skip to content

Setting spring.reactor.context-propagation has no effect when lazy initialization is enabled #45846

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

Open
Akaame opened this issue Jun 6, 2025 · 2 comments
Labels
type: bug A general bug
Milestone

Comments

@Akaame
Copy link

Akaame commented Jun 6, 2025

Setting spring.main.lazy-initialization: true effectively disables the spring.reactor.context-propagation: AUTO, as the ReactorAutoConfiguration1 is never instantiated during the application startup. Turning on eager initialization alleviates this problem, which leads me to believe that this particular setup was overlooked when the AutoConfiguration class what added. Hence, I created this issue, even though the text reads more like a question.

We are currently doing the following

@AutoConfiguration
@ConditionalOnClass(Hooks.class)
@EnableConfigurationProperties(ReactorProperties.class)
@Lazy(false)
public class EagerReactorAutoConfiguration {
  EagerReactorAutoConfiguration(ReactorProperties properties) {
    if (properties.getContextPropagation() == ReactorProperties.ContextPropagationMode.AUTO) {
      Hooks.enableAutomaticContextPropagation();
    }
  }
}

This is not elegant at all and I am not super sure if there is a way of forcing eager auto configuration for such cases (or if this should be rather fixed at Spring Boot level).

Cheers!

Footnotes

  1. ReactorAutoConfiguration

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jun 6, 2025
@wilkinsona
Copy link
Member

You're right, this is a bug. Until it's fixed, you can use a filter to exclude the ReactorAutoConfiguration bean from lazy init:

@Bean
LazyInitializationExcludeFilter eagerReactorAutoConfiguration() {
	return LazyInitializationExcludeFilter.forBeanTypes(ReactorAutoConfiguration.class);
}

@wilkinsona wilkinsona added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Jun 6, 2025
@wilkinsona wilkinsona added this to the 3.4.x milestone Jun 6, 2025
@wilkinsona wilkinsona changed the title ReactorAutoConfiguration and Lazy Initialization Setting spring.reactor.context-propagation has no effect when lazy initialization is enabled Jun 6, 2025
@Akaame
Copy link
Author

Akaame commented Jun 6, 2025

That worked out perfectly for our setup. Thanks for the quick answer @wilkinsona 🍺

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

3 participants