{"record":{"id":"1038d6066d707b50","repo":"spring-projects/spring-security","slug":"expected-single-matching-bean-of-type-org-springf","errorCode":null,"errorMessage":"Expected single matching bean of type 'org.springframework.security.oauth2.client.web.OAuth2AuthorizedClientRepository' but found {}: {}","messagePattern":"Expected single matching bean of type 'org\\.springframework\\.security\\.oauth2\\.client\\.web\\.OAuth2AuthorizedClientRepository' but found (.+?): (.+?)","errorType":"exception","errorClass":"NoUniqueBeanDefinitionException","httpStatus":null,"severity":"error","filePath":"config/src/main/java/org/springframework/security/config/annotation/web/configurers/oauth2/client/OAuth2ClientConfigurerUtils.java","lineNumber":82,"sourceCode":"\t\t\t.getSharedObject(OAuth2AuthorizedClientRepository.class);\n\t\tif (authorizedClientRepository == null) {\n\t\t\tauthorizedClientRepository = getAuthorizedClientRepositoryBean(builder);\n\t\t\tif (authorizedClientRepository == null) {\n\t\t\t\tauthorizedClientRepository = new AuthenticatedPrincipalOAuth2AuthorizedClientRepository(\n\t\t\t\t\t\tgetAuthorizedClientService((builder)));\n\t\t\t}\n\t\t\tbuilder.setSharedObject(OAuth2AuthorizedClientRepository.class, authorizedClientRepository);\n\t\t}\n\t\treturn authorizedClientRepository;\n\t}\n\n\tprivate static <B extends HttpSecurityBuilder<B>> OAuth2AuthorizedClientRepository getAuthorizedClientRepositoryBean(\n\t\t\tB builder) {\n\t\tMap<String, OAuth2AuthorizedClientRepository> authorizedClientRepositoryMap = BeanFactoryUtils\n\t\t\t.beansOfTypeIncludingAncestors(builder.getSharedObject(ApplicationContext.class),\n\t\t\t\t\tOAuth2AuthorizedClientRepository.class);\n\t\tif (authorizedClientRepositoryMap.size() > 1) {\n\t\t\tthrow new NoUniqueBeanDefinitionException(OAuth2AuthorizedClientRepository.class,\n\t\t\t\t\tauthorizedClientRepositoryMap.size(),\n\t\t\t\t\t\"Expected single matching bean of type '\" + OAuth2AuthorizedClientRepository.class.getName()\n\t\t\t\t\t\t\t+ \"' but found \" + authorizedClientRepositoryMap.size() + \": \"\n\t\t\t\t\t\t\t+ StringUtils.collectionToCommaDelimitedString(authorizedClientRepositoryMap.keySet()));\n\t\t}\n\t\treturn (!authorizedClientRepositoryMap.isEmpty() ? authorizedClientRepositoryMap.values().iterator().next()\n\t\t\t\t: null);\n\t}\n\n\tprivate static <B extends HttpSecurityBuilder<B>> OAuth2AuthorizedClientService getAuthorizedClientService(\n\t\t\tB builder) {\n\t\tOAuth2AuthorizedClientService authorizedClientService = getAuthorizedClientServiceBean(builder);\n\t\tif (authorizedClientService == null) {\n\t\t\tauthorizedClientService = new InMemoryOAuth2AuthorizedClientService(\n\t\t\t\t\tgetClientRegistrationRepository(builder));\n\t\t}\n\t\treturn authorizedClientService;\n\t}","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/spring-projects/spring-security/blob/96852e8860138a482cb13d1479573f24ff6443c6/config/src/main/java/org/springframework/security/config/annotation/web/configurers/oauth2/client/OAuth2ClientConfigurerUtils.java#L64-L100","documentation":"When building OAuth2 client support, OAuth2ClientConfigurerUtils looks up an OAuth2AuthorizedClientRepository bean in the ApplicationContext. This IllegalStateException is thrown by getAuthorizedClientRepositoryBean when getBeansOfType finds a number of matching beans other than exactly one (zero or several), because Spring cannot unambiguously pick which repository to use. It fires when no OAuth2AuthorizedClientRepository bean is defined yet a custom one is expected, or when multiple such beans are defined without a primary marker.","triggerScenarios":"Thrown at config/src/main/java/org/springframework/security/config/annotation/web/configurers/oauth2/client/OAuth2ClientConfigurerUtils.java:82 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Define exactly one OAuth2AuthorizedClientRepository bean, or mark the intended one with @Primary","If multiple repositories exist, remove or qualify the redundant beans","Provide no bean at all to let the default AuthenticatedPrincipalOAuth2AuthorizedClientRepository/InMemoryOAuth2AuthorizedClientService be used"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"96852e8860138a482cb13d1479573f24ff6443c6","analyzedAt":"2026-09-10T23:25:23.477Z","contentChangedAt":"2026-09-10T23:25:23.477Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}