{"record":{"id":"3e79146083efea1b","repo":"spring-projects/spring-security","slug":"couldn-t-locate-org-springframework-ldap-core-sup","errorCode":null,"errorMessage":"Couldn't locate: org.springframework.ldap.core.support.BaseLdapPathContextSource. If you are using LDAP with Spring Security, please ensure that you include the spring-ldap jar file in your application","messagePattern":"Couldn't locate: org\\.springframework\\.ldap\\.core\\.support\\.BaseLdapPathContextSource\\. If you are using LDAP with Spring Security, please ensure that you include the spring-ldap jar file in your application","errorType":"exception","errorClass":"ApplicationContextException","httpStatus":null,"severity":"error","filePath":"config/src/main/java/org/springframework/security/config/ldap/ContextSourceSettingPostProcessor.java","lineNumber":75,"sourceCode":"\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) {\n\t\t\tthrow new ApplicationContextException(\"Couldn't locate: \" + REQUIRED_CONTEXT_SOURCE_CLASS_NAME + \". \"\n\t\t\t\t\t+ \" If you are using LDAP with Spring Security, please ensure that you include the spring-ldap \"\n\t\t\t\t\t+ \"jar file in your application\", ex);\n\t\t}\n\t}\n\n\tpublic void setDefaultNameRequired(boolean defaultNameRequired) {\n\t\tthis.defaultNameRequired = defaultNameRequired;\n\t}\n\n\t@Override\n\tpublic int getOrder() {\n\t\treturn LOWEST_PRECEDENCE;\n\t}\n\n}\n","sourceCodeStart":57,"sourceCodeEnd":91,"githubUrl":"https://github.com/spring-projects/spring-security/blob/96852e8860138a482cb13d1479573f24ff6443c6/config/src/main/java/org/springframework/security/config/ldap/ContextSourceSettingPostProcessor.java#L57-L91","documentation":"getContextSourceClass() loads org.springframework.ldap.core.support.BaseLdapPathContextSource reflectively. If spring-ldap is not on the classpath the class cannot be found, and an ApplicationContextException (wrapping ClassNotFoundException) is thrown since LDAP support cannot function without it.","triggerScenarios":"Any LDAP configuration (<ldap-server/>, <ldap-authentication-provider/>, <ldap-user-service/>) present while the spring-ldap-core jar is absent from the application classpath.","commonSituations":"Using spring-security-config LDAP XML namespace without adding the spring-ldap dependency; Maven/Gradle dependency scope wrong (provided/test) so it's missing at runtime; upgrading Spring Security which requires newer spring-ldap.","solutions":["Add spring-ldap-core to dependencies (e.g. org.springframework.ldap:spring-ldap-core).","Verify the dependency isn't marked with a scope/feature that excludes it from the runtime classpath (e.g. 'provided' in a war).","If LDAP is not used, remove the LDAP configuration elements so the post-processor never runs."],"exampleFix":"// before\n<!-- pom.xml: spring-security-config only -->\n\n// after\n<dependency>\n  <groupId>org.springframework.ldap</groupId>\n  <artifactId>spring-ldap-core</artifactId>\n</dependency>","handlingStrategy":"validation","validationCode":"try {\n  ClassUtils.forName(\"org.springframework.ldap.core.support.BaseLdapPathContextSource\",\n      ClassUtils.getDefaultClassLoader());\n} catch (ClassNotFoundException ex) {\n  throw new IllegalStateException(\"Add spring-ldap-core to the classpath\", ex);\n}","typeGuard":null,"tryCatchPattern":"try { enableLdap(); }\ncatch (ApplicationContextException e) {\n  if (e.getMessage().contains(\"Couldn't locate\")) addSpringLdapDependency();\n}","preventionTips":["Add spring-ldap-core whenever any LDAP XML element is used","Check dependency tree (mvn dependency:tree) for spring-ldap","Remove unused LDAP config elements instead of leaving them half-configured"],"tags":["spring-security","ldap","classpath","missing-dependency"],"backgroundTag":"class-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"}