{"record":{"id":"e9f43b428b6b22af","repo":"spring-projects/spring-security","slug":"no-baseldappathcontextsource-instances-found-have","errorCode":null,"errorMessage":"No BaseLdapPathContextSource instances found. Have you added an <ldap-server /> element to your application context? If you have declared an explicit bean, do not use lazy-init","messagePattern":"No BaseLdapPathContextSource instances found\\. Have you added an <ldap-server /> element to your application context\\? If you have declared an explicit bean, do not use lazy-init","errorType":"exception","errorClass":"ApplicationContextException","httpStatus":null,"severity":"error","filePath":"config/src/main/java/org/springframework/security/config/ldap/ContextSourceSettingPostProcessor.java","lineNumber":56,"sourceCode":"public class ContextSourceSettingPostProcessor implements BeanFactoryPostProcessor, Ordered {\n\n\tprivate static final String REQUIRED_CONTEXT_SOURCE_CLASS_NAME = \"org.springframework.ldap.core.support.BaseLdapPathContextSource\";\n\n\t/**\n\t * If set to true, a bean parser has indicated that the default context source name\n\t * needs to be set.\n\t */\n\tprivate boolean defaultNameRequired;\n\n\tContextSourceSettingPostProcessor() {\n\t}\n\n\t@Override\n\tpublic void postProcessBeanFactory(ConfigurableListableBeanFactory bf) throws BeansException {\n\t\tClass<?> contextSourceClass = getContextSourceClass();\n\t\tString[] sources = bf.getBeanNamesForType(contextSourceClass, false, false);\n\t\tif (sources.length == 0) {\n\t\t\tthrow new ApplicationContextException(\"No BaseLdapPathContextSource instances found. Have you \"\n\t\t\t\t\t+ \"added an <\" + Elements.LDAP_SERVER + \" /> element to your application context? If you have \"\n\t\t\t\t\t+ \"declared an explicit bean, do not use lazy-init\");\n\t\t}\n\t\tif (!bf.containsBean(BeanIds.CONTEXT_SOURCE) && this.defaultNameRequired) {\n\t\t\tif (sources.length > 1) {\n\t\t\t\tthrow new ApplicationContextException(\"More than one BaseLdapPathContextSource instance found. \"\n\t\t\t\t\t\t+ \"Please specify a specific server id using the 'server-ref' attribute when configuring your <\"\n\t\t\t\t\t\t+ Elements.LDAP_PROVIDER + \"> \" + \"or <\" + Elements.LDAP_USER_SERVICE + \">.\");\n\t\t\t}\n\t\t\tbf.registerAlias(sources[0], BeanIds.CONTEXT_SOURCE);\n\t\t}\n\t}\n\n\tprivate Class<?> getContextSourceClass() throws LinkageError {\n\t\ttry {\n\t\t\treturn ClassUtils.forName(REQUIRED_CONTEXT_SOURCE_CLASS_NAME, ClassUtils.getDefaultClassLoader());\n\t\t}\n\t\tcatch (ClassNotFoundException ex) {","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/spring-projects/spring-security/blob/96852e8860138a482cb13d1479573f24ff6443c6/config/src/main/java/org/springframework/security/config/ldap/ContextSourceSettingPostProcessor.java#L38-L74","documentation":"ContextSourceSettingPostProcessor.postProcessBeanFactory() requires at least one BaseLdapPathContextSource bean for LDAP configuration. When none is found it throws, hinting that the <ldap-server/> element is missing or the context source bean is lazy and therefore never instantiated.","triggerScenarios":"Using <ldap-authentication-provider/>, <ldap-user-service/>, or related LDAP elements without any BaseLdapPathContextSource bean present (no <ldap-server/> and no explicit context source bean, or the explicit bean is lazy-init so it isn't registered/instantiable eagerly).","commonSituations":"Forgetting <ldap-server/> while using <ldap-authentication-provider/>; declaring a DefaultSpringSecurityContextSource bean with lazy-init=\"true\"; LDAP elements retained after removing the embedded server.","solutions":["Add <ldap-server/> to the configuration (embedded or pointing to ldif).","Declare an explicit BaseLdapPathContextSource bean (e.g. DefaultSpringSecurityContextSource) without lazy-init.","If a lazy bean is required, set default-lazy-init=\"false\" on it or reference it explicitly via server-ref."],"exampleFix":"// before\n<ldap-authentication-provider user-search-filter=\"(uid={0})\" user-search-base=\"ou=people\"/>\n\n// after\n<ldap-server url=\"ldap://localhost:8389/dc=springframework,dc=org\"/>\n<ldap-authentication-provider user-search-filter=\"(uid={0})\" user-search-base=\"ou=people\"/>","handlingStrategy":"validation","validationCode":"String[] names = bf.getBeanNamesForType(BaseLdapPathContextSource.class, false, false);\nif (names.length == 0) {\n  throw new IllegalStateException(\"Add <ldap-server/> or a non-lazy BaseLdapPathContextSource bean\");\n}","typeGuard":null,"tryCatchPattern":"try { ctx.refresh(); }\ncatch (ApplicationContextException e) {\n  if (e.getMessage().contains(\"No BaseLdapPathContextSource\")) log.error(\"Missing <ldap-server/>\");\n}","preventionTips":["Always include <ldap-server/> when using LDAP namespace elements","Never set lazy-init on BaseLdapPathContextSource beans","Boot the context in tests to catch config errors early"],"tags":["spring-security","ldap","missing-bean","config"],"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"}