{"record":{"id":"06ae8e141fd4d8c3","repo":"spring-projects/spring-security","slug":"no-userdetailsservice-registered","errorCode":null,"errorMessage":"No UserDetailsService registered.","messagePattern":"No UserDetailsService registered\\.","errorType":"exception","errorClass":"ApplicationContextException","httpStatus":null,"severity":"error","filePath":"config/src/main/java/org/springframework/security/config/http/UserDetailsServiceFactoryBean.java","lineNumber":108,"sourceCode":"\t\t\t\tthrow new ApplicationContextException(\n\t\t\t\t\t\t\"Bean '\" + name + \"' must be a UserDetailsService or an\" + \" AuthenticationUserDetailsService\");\n\t\t\t}\n\t\t}\n\t\treturn new UserDetailsByNameServiceWrapper(uds);\n\t}\n\n\t/**\n\t * Obtains a user details service for use in RememberMeServices etc. Will return a\n\t * caching version if available so should not be used for beans which need to separate\n\t * the two.\n\t */\n\tprivate UserDetailsService getUserDetailsService() {\n\t\tMap<String, ?> beans = getBeansOfType(CachingUserDetailsService.class);\n\t\tif (beans.isEmpty()) {\n\t\t\tbeans = getBeansOfType(UserDetailsService.class);\n\t\t}\n\t\tif (beans.isEmpty()) {\n\t\t\tthrow new ApplicationContextException(\"No UserDetailsService registered.\");\n\t\t}\n\t\tif (beans.size() > 1) {\n\t\t\tthrow new ApplicationContextException(\"More than one UserDetailsService registered. Please \"\n\t\t\t\t\t+ \"use a specific Id reference in <remember-me/> or <x509 /> elements.\");\n\t\t}\n\t\treturn (UserDetailsService) beans.values().toArray()[0];\n\t}\n\n\t@Override\n\tpublic void setApplicationContext(ApplicationContext beanFactory) throws BeansException {\n\t\tthis.beanFactory = beanFactory;\n\t}\n\n\tprivate Map<String, ?> getBeansOfType(Class<?> type) {\n\t\tMap<String, ?> beans = this.beanFactory.getBeansOfType(type);\n\t\t// Check ancestor bean factories if they exist and the current one has none of the\n\t\t// required type\n\t\tBeanFactory parent = this.beanFactory.getParentBeanFactory();","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/spring-projects/spring-security/blob/96852e8860138a482cb13d1479573f24ff6443c6/config/src/main/java/org/springframework/security/config/http/UserDetailsServiceFactoryBean.java#L90-L126","documentation":"UserDetailsServiceFactoryBean.getUserDetailsService() looks up UserDetailsService beans in the context (preferring CachingUserDetailsService). When none exist, it throws because remember-me/x509 auto-configuration has no user source to authenticate tokens against.","triggerScenarios":"Using <remember-me/> or <x509/> without an id ref while the application context contains zero beans of type UserDetailsService or CachingUserDetailsService.","commonSituations":"In-memory user store defined only via AuthenticationManagerBuilder without exposing a UserDetailsService bean; all user details beans removed during refactor; custom AuthenticationProvider used without a UserDetailsService.","solutions":["Register a UserDetailsService bean (e.g. InMemoryUserDetailsManager, JdbcUserDetailsManager, or custom) in the context.","If more than one is intended, add an explicit id via remember-me's service-ref or x509's service-ref.","For custom authentication logic, expose a UserDetailsService so Spring Security can resolve it."],"exampleFix":"// before\n<http>\n  <remember-me key=\"myKey\"/>\n</http>\n\n// after\n<bean id=\"uds\" class=\"org.springframework.security.core.userdetails.memory.InMemoryUserDetailsManager\">\n  <property name=\"userProperties\"><value>user=pass,ROLE_USER</value></property>\n</bean>\n<http>\n  <remember-me key=\"myKey\" service-ref=\"uds\"/>\n</http>","handlingStrategy":"validation","validationCode":"if (ctx.getBeansOfType(UserDetailsService.class).isEmpty()) {\n    throw new IllegalStateException(\"Register a UserDetailsService before enabling remember-me/x509\");\n}","typeGuard":null,"tryCatchPattern":"try { buildContext(); }\ncatch (ApplicationContextException e) {\n  if (e.getMessage().contains(\"No UserDetailsService\")) registerDefaultUds();\n}","preventionTips":["Always expose at least one UserDetailsService bean","Prefer explicit service-ref over implicit lookup","Test context startup in CI with the full XML/Java config"],"tags":["spring-security","config","missing-bean","userdetailsservice"],"backgroundTag":"entity-not-found","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"}