Skip to content

Add @ConditionalOnWebApplication to ReactiveOAuth2ResourceServerAutoConfiguration#49812

Closed
daguimu wants to merge 1 commit intospring-projects:mainfrom
daguimu:fix/reactive-oauth2-conditional-on-web-type
Closed

Add @ConditionalOnWebApplication to ReactiveOAuth2ResourceServerAutoConfiguration#49812
daguimu wants to merge 1 commit intospring-projects:mainfrom
daguimu:fix/reactive-oauth2-conditional-on-web-type

Conversation

@daguimu
Copy link
Copy Markdown

@daguimu daguimu commented Mar 27, 2026

Problem

When a Servlet-based application includes dependencies that pull in reactor-core (e.g., spring-boot-starter-data-redis via Lettuce), ReactiveOAuth2ResourceServerAutoConfiguration is triggered incorrectly, causing a NoClassDefFoundError for WebClient at startup.

Root Cause

ReactiveOAuth2ResourceServerAutoConfiguration only checks for the presence of Mono.class and BearerTokenAuthenticationToken.class via @ConditionalOnClass. Since libraries like Lettuce bring reactor-core (and thus Mono) onto the classpath for their own async internals, the condition is satisfied even in Servlet-based applications. The imported ReactiveJwtDecoderConfiguration then attempts to create a NimbusReactiveJwtDecoder which requires WebClient from spring-webflux, which is not present.

Fix

  • Added @ConditionalOnWebApplication(type = Type.REACTIVE) to ReactiveOAuth2ResourceServerAutoConfiguration to ensure it only activates for reactive web applications
  • This is consistent with ReactiveOAuth2ResourceServerWebSecurityAutoConfiguration, which already has this condition

Tests Added

Change Point Test
Added @ConditionalOnWebApplication(type = Type.REACTIVE) autoConfigurationShouldBeConditionalOnReactiveWebApplication() — verifies that no ReactiveJwtDecoder or ReactiveOpaqueTokenIntrospector beans are created when running in a Servlet web application context

Impact

Only affects the activation condition of the reactive OAuth2 resource server auto-configuration. Servlet-based applications will no longer incorrectly trigger this configuration. Reactive web applications are unaffected as the condition is satisfied in that context.

Fixes #49807

…onfiguration

ReactiveOAuth2ResourceServerAutoConfiguration was only conditional on
the presence of Mono and BearerTokenAuthenticationToken classes. When a
Servlet-based application includes dependencies that pull in
reactor-core (e.g., spring-boot-starter-data-redis via Lettuce), the
auto-configuration was triggered incorrectly, causing a
NoClassDefFoundError for WebClient at startup.

Add @ConditionalOnWebApplication(type = Type.REACTIVE) to ensure the
auto-configuration only activates for reactive web applications,
consistent with ReactiveOAuth2ResourceServerWebSecurityAutoConfiguration.

Fixes spring-projects#49807
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Mar 27, 2026
@wilkinsona
Copy link
Copy Markdown
Member

Thanks for the PR but this isn't the right fix as it would regress #43978.

@wilkinsona wilkinsona closed this Mar 27, 2026
@wilkinsona wilkinsona added status: declined A suggestion or change that we don't feel we should currently apply and removed status: waiting-for-triage An issue we've not yet triaged labels Mar 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: declined A suggestion or change that we don't feel we should currently apply

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ReactiveOAuth2ResourceServerAutoConfiguration should trigger only on real Reactive Applications

3 participants