Consider defining a bean of type 'org.springframework.security.oauth2.client.registration.ReactiveClientRegistrationRepository' in your configuration
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
If you have encountered the error "Consider defining a bean of type 'org.springframework.security.oauth2.client.registration.ReactiveClientRegistrationRepository' in your configuration," you are not alone. This is one of the most common Spring Boot startup failures when integrating OAuth2 with a reactive (WebFlux) application. It means Spring's dependency injection container cannot find a bean that implements ReactiveClientRegistrationRepository, and your security configuration or an auto-configured component requires one.
This article explains what the repository does, why the error occurs, and how to fix it with working configuration examples.
What Is ReactiveClientRegistrationRepository?
ReactiveClientRegistrationRepository is the reactive counterpart of ClientRegistrationRepository in Spring Security's OAuth2 client module. It stores ClientRegistration objects, each of which holds the details needed to perform an OAuth2 flow: client ID, client secret, authorization URI, token URI, scopes, and redirect URI.
In a WebFlux application, all I/O should be non-blocking. The reactive version of the repository returns Mono<ClientRegistration> instead of a plain ClientRegistration, fitting naturally into the reactive pipeline.
Why the Error Occurs
Spring Boot auto-configures a ReactiveClientRegistrationRepository bean when it finds spring.security.oauth2.client.registration.* properties in your configuration. The error appears when one of these conditions is true:
- You added
spring-boot-starter-oauth2-clientto your dependencies but did not provide any client registration properties. - Your
application.ymlorapplication.propertieshas a typo in the property path. - You are using a custom security configuration that references the repository, but you removed or never added the auto-configuration properties.
Fixing the Error with Application Properties
The simplest fix is to define at least one client registration in your application.yml.
Spring Boot reads these properties at startup and automatically creates an InMemoryReactiveClientRegistrationRepository bean. No additional Java configuration is needed for this approach.
Defining the Bean Manually
When you need more control, for example loading registrations from a database or a remote config service, you can define the bean explicitly in a configuration class.
This explicit approach is useful when you need to register multiple providers programmatically or pull credentials from a secrets manager like AWS Secrets Manager or HashiCorp Vault.
Using the Repository in a WebFlux Security Configuration
Once the bean exists, you can wire it into your security filter chain.
Spring will automatically inject the ReactiveClientRegistrationRepository into the OAuth2 login configuration. You do not need to pass it manually.
Common Pitfalls
- Mixing servlet and reactive dependencies. If your project includes both
spring-boot-starter-webandspring-boot-starter-webflux, Spring Boot defaults to servlet mode. The reactive repository will not be auto-configured. Removespring-boot-starter-webif you intend to run a WebFlux application. - Forgetting the registration ID. Every
ClientRegistrationmust have a uniqueregistrationId. This ID is used in redirect URIs and in the repository lookup. Omitting it causes a build-time error on theClientRegistration.Builder. - Storing secrets in plain text. Never commit
client-secretvalues to version control. Use environment variables, Spring Cloud Config with encryption, or a secrets manager. You can reference environment variables inapplication.ymlwith${GITHUB_CLIENT_SECRET}. - Using the wrong repository type.
ClientRegistrationRepository(non-reactive) works with Spring MVC.ReactiveClientRegistrationRepositoryworks with Spring WebFlux. Using the wrong one produces a bean-not-found error that can be confusing, because both have similar names.
Summary
The "consider defining a bean" error for ReactiveClientRegistrationRepository is a configuration issue, not a code bug. It is resolved either by providing OAuth2 client properties in application.yml (which triggers auto-configuration) or by defining the bean manually in a @Configuration class. Make sure your project uses the reactive web starter, keep secrets out of source control, and verify that each registration has a unique ID. With these steps, the error disappears and your reactive OAuth2 flow works as expected.
Related reading
- Constant-Time comparison
- Convert JWT Authentication Principal to something more usable in spring
- Correct use of WebSecurity in WebSecurityConfigurerAdapter
- Correct way to attach AWS managed policies to a role?
- Consider defining a bean of type 'package' in your configuration Spring-Boot
- Consider defining a bean of type 'package' in your configuration Spring-Boot
- Cors Error when using CorsFilter and spring security
- CORS issue with Spring Boot

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseSystem Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.