Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Security and hardening

Spring Boot cannot find a ClientRegistrationRepository bean for OAuth2 login

ErrorParameter 0 of constructor ... required a bean of type 'org.springframework.security.oauth2.client.registration.ClientRegistrationRepository' that could not be found

Short 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.

  • Applies to Spring Boot 3.5, Spring Security 6.5, Java 21
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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.security
  2. 2Match what you see, then jump to its fix

    1. 1The 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. 2The id is something like google-login or my-google and no provider is namedThe registration id does not match a known providerFix
    3. 3The 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

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 found
  • APPLICATION 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 google

Confirmed by docs.spring.io

Did this fix it?

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:run

Confirmed by docs.spring.io

Did this fix it?

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/java

2Fix

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:run

Confirmed by docs.spring.io

Did this fix it?

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

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.