Spring Boot cannot find a ClientRegistrationRepository bean for OAuth2 login
Parameter 0 of constructor ... required a bean of type 'org.springframework.security.oauth2.client.registration.ClientRegistrationRepository' that could not be foundShort answer
Boot creates the ClientRegistrationRepository from spring.security.oauth2.client.registration properties. With no registration configured, or after you replace auto-configuration, no bean exists. Add a registration with client-id and client-secret, or declare the bean yourself.
Fix it fast
1Find out which cause you have
Check which OAuth2 client properties the running app actually sees, and which profile is active. An empty registration block is the most common cause.
grep -rn "oauth2" src/main/resources/application*.y*ml src/main/resources/application*.properties ./mvnw dependency:tree -Dincludes=org.springframework.security2Match what you see, then jump to its fix
- 1
The properties file has no spring.security.oauth2.client.registration entry, or it is in a profile that is not activeNo client registration is configuredFix - 2
The id is something like google-login or my-google and no provider is namedThe registration id does not match a known providerFix - 3
The error appears after adding your own SecurityFilterChain or an @EnableWebSecurity class with oauth2Login()You declared your own security setup and the auto-configuration stepped asideFix
- 1
What does the error look like?
Parameter 0 of constructor ... required a bean of type 'org.springframework.security.oauth2.client.registration.ClientRegistrationRepository' that could not be foundAPPLICATION FAILED TO START
Cause 1 of 3
No client registration is configured
1Check
Boot registers the repository from the client properties. Without any, there is nothing to register.
grep -rn "registration" src/main/resources/2Fix
Add the registration. For Google, only the client id and secret are needed because the registration id google matches a built-in provider.
spring:
security:
oauth2:
client:
registration:
google:
client-id: ${GOOGLE_CLIENT_ID}
client-secret: ${GOOGLE_CLIENT_SECRET}3Verify
Start the app and open /login; it should list the Google link.
curl -s http://localhost:8080/login | grep -i googleConfirmed by docs.spring.io
Cause 2 of 3
The registration id does not match a known provider
1Check
Defaults are applied when the registration id matches a provider such as GOOGLE, ignoring case. Any other id needs an explicit provider.
grep -rn -A3 "registration:" src/main/resources/2Fix
Name the provider on the registration.
spring:
security:
oauth2:
client:
registration:
google-login:
provider: google
client-id: ${GOOGLE_CLIENT_ID}
client-secret: ${GOOGLE_CLIENT_SECRET}3Verify
Restart and confirm the app starts.
./mvnw -q spring-boot:runConfirmed by docs.spring.io
Cause 3 of 3
You declared your own security setup and the auto-configuration stepped aside
1Check
OAuth2ClientAutoConfiguration registers the repository from properties and a default SecurityFilterChain. You can override either or both. If you wrote the filter chain but have no properties, nothing provides the repository.
grep -rn "oauth2Login\|ClientRegistrationRepository" src/main/java2Fix
Either keep the properties (the repository bean is then still created), or register a ClientRegistrationRepository bean in your configuration.
@Bean
ClientRegistrationRepository clientRegistrationRepository() {
return new InMemoryClientRegistrationRepository(
CommonOAuth2Provider.GOOGLE.getBuilder("google")
.clientId("google-client-id")
.clientSecret("google-client-secret")
.build());
}3Verify
Restart the app.
./mvnw -q spring-boot:runConfirmed by docs.spring.io
How do I stop it coming back?
- Keep client id and secret in environment variables and reference them with ${...} in properties.
- Run a context-load test in CI with the production property names so a missing registration fails the build.
- Use the provider's registration id exactly (google, github) unless you set provider explicitly.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Security
Jwts.parserBuilder() no longer compiles after upgrading JJWT
setSigningKey / parseClaimsJws / getBody shown as deprecated
JJWT 0.12.0 removed Jwts.parserBuilder() because Jwts.parser() now returns the builder itself.
3 causes, each with a fixSecurity
Spring Security fails to resolve the issuer configuration for a JWT or Keycloak
The identity server is up but the Spring app fails on the first token
Spring Security fetches the issuer's discovery document before it can validate tokens.
3 causes, each with a fixSecurity
Spring Security cannot verify the CSRF token because the session is gone
InvalidCsrfTokenException
By default Spring Security keeps the expected CSRF token in the HTTP session.
3 causes, each with a fixSecurity
POST requests return 403 in Spring Security because the CSRF token is missing
MissingCsrfTokenException
Spring Security checks a CSRF token on every request except GET, HEAD, TRACE and OPTIONS.
4 causes, each with a fixSecurity
Changing the error response when a JWT is rejected in Spring Security
403 Forbidden for a valid token that lacks the required authority
A resource server answers a bad token with 401 and a WWW-Authenticate header, and a valid token without enough rights with 403.
2 causes, each with a fixSecurity
A Microsoft Entra access token shows Invalid Signature when you check it yourself
Tokens that a Microsoft API receives might not always be a JWT that can be decoded
A token issued for Microsoft Graph is not meant for you to validate, so a failed signature check is expected.
2 causes, each with a fix