{"record":{"id":"b86bc17bde2f31dc","repo":"spring-projects/spring-security","slug":"unable-to-create-an-oauth2authorizedclientmanager","errorCode":null,"errorMessage":"Unable to create an {OAuth2AuthorizedClientManager} bean. Expected one bean of type {authorizedClientProvider.getClass().getName()}, but found multiple. Please consider defining only a single bean of this type, or define an {OAuth2AuthorizedClientManager} bean yourself.","messagePattern":"Unable to create an (.+?) bean\\. Expected one bean of type (.+?), but found multiple\\. Please consider defining only a single bean of this type, or define an (.+?) bean yourself\\.","errorType":"exception","errorClass":"BeanInitializationException","httpStatus":null,"severity":"error","filePath":"config/src/main/java/org/springframework/security/config/annotation/web/configuration/OAuth2ClientConfiguration.java","lineNumber":395,"sourceCode":"\t\t}\n\n\t\tprivate <T extends OAuth2AuthorizedClientProvider> T getAuthorizedClientProviderByType(\n\t\t\t\tCollection<OAuth2AuthorizedClientProvider> authorizedClientProviders, Class<T> providerClass) {\n\t\t\tT authorizedClientProvider = null;\n\t\t\tfor (OAuth2AuthorizedClientProvider current : authorizedClientProviders) {\n\t\t\t\tif (providerClass.isInstance(current)) {\n\t\t\t\t\tassertAuthorizedClientProviderIsNull(authorizedClientProvider);\n\t\t\t\t\tauthorizedClientProvider = providerClass.cast(current);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn authorizedClientProvider;\n\t\t}\n\n\t\tprivate static void assertAuthorizedClientProviderIsNull(\n\t\t\t\tOAuth2AuthorizedClientProvider authorizedClientProvider) {\n\t\t\tif (authorizedClientProvider != null) {\n\t\t\t\t// @formatter:off\n\t\t\t\tthrow new BeanInitializationException(String.format(\n\t\t\t\t\t\t\"Unable to create an %s bean. Expected one bean of type %s, but found multiple. \" +\n\t\t\t\t\t\t\"Please consider defining only a single bean of this type, or define an %s bean yourself.\",\n\t\t\t\t\t\tOAuth2AuthorizedClientManager.class.getName(),\n\t\t\t\t\t\tauthorizedClientProvider.getClass().getName(),\n\t\t\t\t\t\tOAuth2AuthorizedClientManager.class.getName()));\n\t\t\t\t// @formatter:on\n\t\t\t}\n\t\t}\n\n\t\tprivate <T> String[] getBeanNamesForType(Class<T> beanClass) {\n\t\t\treturn BeanFactoryUtils.beanNamesForTypeIncludingAncestors(this.beanFactory, beanClass, true, true);\n\t\t}\n\n\t\tprivate <T> T getBeanOfType(ResolvableType resolvableType) {\n\t\t\tObjectProvider<T> objectProvider = this.beanFactory.getBeanProvider(resolvableType, true);\n\t\t\treturn objectProvider.getIfAvailable();\n\t\t}\n","sourceCodeStart":377,"sourceCodeEnd":413,"githubUrl":"https://github.com/spring-projects/spring-security/blob/96852e8860138a482cb13d1479573f24ff6443c6/config/src/main/java/org/springframework/security/config/annotation/web/configuration/OAuth2ClientConfiguration.java#L377-L413","documentation":"Spring's OAuth2 client configuration tries to create a default OAuth2AuthorizedClientManager from a single OAuth2AuthorizedClientProvider bean found in the context. If multiple OAuth2AuthorizedClientProvider beans exist, the configuration cannot decide which to use and throws BeanInitializationException telling you to keep one provider or define your own OAuth2AuthorizedClientManager.","triggerScenarios":"Defining more than one OAuth2AuthorizedClientProvider @Bean (e.g. one for authorization_code and one for client_credentials) while relying on the auto-configured OAuth2AuthorizedClientManager; libraries contributing an additional provider bean.","commonSituations":"OAuth2 client apps where developers register several providers for different grant types; Spring Boot apps adding both custom and framework provider beans; upgrade scenarios where auto-configuration began consuming provider beans.","solutions":["Keep only one OAuth2AuthorizedClientProvider bean, or compose them into one (e.g. a chain-of-responsibility provider) and expose that single bean","Define your own OAuth2AuthorizedClientManager @Bean so the ambiguous auto-configuration path is skipped","Mark one provider @Primary or use qualifiers if multiple must coexist with a manually built manager"],"exampleFix":"// before\n@Bean OAuth2AuthorizedClientProvider authCodeProvider() { ... }\n@Bean OAuth2AuthorizedClientProvider clientCredsProvider() { ... }\n// after\n@Bean\nOAuth2AuthorizedClientProvider provider() {\n    return new DelegatingOAuth2AuthorizedClientProvider(authCodeProvider(), clientCredsProvider());\n}","handlingStrategy":"validation","validationCode":"String[] names = context.getBeanNamesForType(OAuth2AuthorizedClientProvider.class);\nif (names.length > 1 && context.getBeanNamesForType(OAuth2AuthorizedClientManager.class).length == 0) {\n    throw new IllegalStateException(\n        \"Multiple OAuth2AuthorizedClientProvider beans; define an OAuth2AuthorizedClientManager explicitly\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    context.getBean(OAuth2AuthorizedClientManager.class);\n} catch (NoSuchBeanDefinitionException | BeanCreationException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"found multiple\")) {\n        // register a DelegatingOAuth2AuthorizedClientProvider and your own manager\n    }\n    throw e;\n}","preventionTips":["Compose multiple grant-type providers into one DelegatingOAuth2AuthorizedClientProvider bean","Define an explicit OAuth2AuthorizedClientManager when you have custom providers","Audit third-party starters that may contribute their own OAuth2AuthorizedClientProvider bean"],"tags":["spring-security","oauth2","bean-ambiguity","auto-configuration"],"backgroundTag":"conflicting-config-options","analyzedSha":"96852e8860138a482cb13d1479573f24ff6443c6","analyzedAt":"2026-09-10T23:25:23.477Z","contentChangedAt":"2026-09-10T23:25:23.477Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}