{"record":{"id":"889aa38b2857a950","repo":"spring-projects/spring-security","slug":"the-clientregistration-with-id-clientregistrati","errorCode":null,"errorMessage":"The ClientRegistration with id '${clientRegistrationId}' exists in the data source, however, it was not found in the ClientRegistrationRepository.","messagePattern":"The ClientRegistration with id '(.+?)' exists in the data source, however, it was not found in the ClientRegistrationRepository\\.","errorType":"exception","errorClass":"DataRetrievalFailureException","httpStatus":null,"severity":"error","filePath":"oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/JdbcOAuth2AuthorizedClientService.java","lineNumber":262,"sourceCode":"\t\tprotected LobHandler lobHandler = new DefaultLobHandler();\n\n\t\tpublic OAuth2AuthorizedClientRowMapper(ClientRegistrationRepository clientRegistrationRepository) {\n\t\t\tAssert.notNull(clientRegistrationRepository, \"clientRegistrationRepository cannot be null\");\n\t\t\tthis.clientRegistrationRepository = clientRegistrationRepository;\n\t\t}\n\n\t\tpublic final void setLobHandler(LobHandler lobHandler) {\n\t\t\tAssert.notNull(lobHandler, \"lobHandler cannot be null\");\n\t\t\tthis.lobHandler = lobHandler;\n\t\t}\n\n\t\t@Override\n\t\tpublic OAuth2AuthorizedClient mapRow(ResultSet rs, int rowNum) throws SQLException {\n\t\t\tString clientRegistrationId = rs.getString(\"client_registration_id\");\n\t\t\tClientRegistration clientRegistration = this.clientRegistrationRepository\n\t\t\t\t.findByRegistrationId(clientRegistrationId);\n\t\t\tif (clientRegistration == null) {\n\t\t\t\tthrow new DataRetrievalFailureException(\n\t\t\t\t\t\t\"The ClientRegistration with id '\" + clientRegistrationId + \"' exists in the data source, \"\n\t\t\t\t\t\t\t\t+ \"however, it was not found in the ClientRegistrationRepository.\");\n\t\t\t}\n\t\t\tOAuth2AccessToken.TokenType tokenType = null;\n\t\t\tif (OAuth2AccessToken.TokenType.BEARER.getValue().equalsIgnoreCase(rs.getString(\"access_token_type\"))) {\n\t\t\t\ttokenType = OAuth2AccessToken.TokenType.BEARER;\n\t\t\t}\n\t\t\tOAuth2AccessToken.TokenType tokenTypeToUse = (tokenType != null) ? tokenType\n\t\t\t\t\t: OAuth2AccessToken.TokenType.BEARER;\n\t\t\tString tokenValue = new String(this.lobHandler.getBlobAsBytes(rs, \"access_token_value\"),\n\t\t\t\t\tStandardCharsets.UTF_8);\n\t\t\tTimestamp issuedAtTs = rs.getTimestamp(\"access_token_issued_at\");\n\t\t\tTimestamp expiresAtTs = rs.getTimestamp(\"access_token_expires_at\");\n\t\t\tInstant issuedAt = (issuedAtTs != null) ? issuedAtTs.toInstant() : null;\n\t\t\tInstant expiresAt = (expiresAtTs != null) ? expiresAtTs.toInstant() : null;\n\t\t\tSet<String> scopes = Collections.emptySet();\n\t\t\tString accessTokenScopes = rs.getString(\"access_token_scopes\");\n\t\t\tif (accessTokenScopes != null) {","sourceCodeStart":244,"sourceCodeEnd":280,"githubUrl":"https://github.com/spring-projects/spring-security/blob/96852e8860138a482cb13d1479573f24ff6443c6/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/JdbcOAuth2AuthorizedClientService.java#L244-L280","documentation":"JdbcOAuth2AuthorizedClientService.OAuth2AuthorizedClientRowMapper loads an OAuth2AuthorizedClient row from the database and resolves the ClientRegistration via the configured ClientRegistrationRepository. When the repository cannot find a registration matching the row's client_registration_id, it throws this DataRetrievalFailureException, because an authorized client row without a corresponding in-memory registration cannot be reconstructed.","triggerScenarios":"Calling loadAuthorizedClient/removeAuthorizedClient/updateAuthorizedClient on JdbcOAuth2AuthorizedClientService when the oauth2_authorized_client table contains a row whose client_registration_id is not registered in the ClientRegistrationRepository (which is typically an InMemoryClientRegistrationRepository built from static spring.security.oauth2.client.registration.* properties).","commonSituations":"Client registration removed or renamed in application.yml while old authorized-client rows persist in the database; multi-tenant setups where rows are written for registrations that are not loaded on that instance; switching from a dynamic/OIDC-discovery repository to a static one; running multiple apps or profiles against a shared database.","solutions":["Delete or clean stale rows in oauth2_authorized_client whose client_registration_id no longer exists in the repository.","Restore the missing registration in your ClientRegistrationRepository / application properties so the id matches the DB rows.","If registrations are dynamic, use a ClientRegistrationRepository that can resolve all persisted registration ids (e.g. a Jdbc-backed or issuer-based repository).","Use a custom RowMapper or wrap the service to skip/log rows whose registration is absent instead of failing the whole load."],"exampleFix":"// before: stale DB rows for removed client 'old-client'\nspring.security.oauth2.client.registration.old-client.client-id=...\n// after: either re-add the registration or purge rows\nDELETE FROM oauth2_authorized_client WHERE client_registration_id = 'old-client';","handlingStrategy":"try-catch","validationCode":"boolean registered = clientRegistrationRepository.findByRegistrationId(rowId) != null;\nif (!registered) { /* skip/purge row or re-add registration */ }","typeGuard":"boolean hasRegistration(String id) {\n    return clientRegistrationRepository.findByRegistrationId(id) != null;\n}","tryCatchPattern":"try {\n    OAuth2AuthorizedClient client = service.loadAuthorizedClient(registrationId, principalName);\n} catch (DataRetrievalFailureException ex) {\n    // purge stale row or fall back to a fresh authorization flow\n    log.warn(\"orphaned authorized client row: {}\", ex.getMessage());\n}","preventionTips":["Treat ClientRegistrationRepository and the DB as one unit: migrate/clean oauth2_authorized_client rows whenever registrations are renamed or removed.","Use a shared/JDBC-backed registration repository when clients are managed dynamically.","Monitor for the error to detect config drift between properties and database."],"tags":["oauth2","jdbc","spring-security","data-retrieval"],"backgroundTag":"record-not-found","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"}