spring-ldap-2.2.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:ldap="http://www.springframework.org/schema/ldap"
xmlns:repository="http://www.springframework.org/schema/data/repository"
elementFormDefault="qualified"
targetNamespace="http://www.springframework.org/schema/ldap">
<xs:import namespace="http://www.springframework.org/schema/data/repository"
schemaLocation="http://www.springframework.org/schema/data/repository/spring-repository.xsd" />
......
<xs:element name="repositories">
<xs:complexType>
<xs:complexContent>
<xs:extension base="repository:repositories">
<xs:attribute name="ldap-template-ref">
<xs:annotation>
<xs:documentation>
The reference to an LdapTemplate. Will default to 'ldapTemplate'.
</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:element>
</xs:schema>
spring-data-commons-2.1.10.RELEASE.jar 中的 spring.schemas
https\://www.springframework.org/schema/data/repository/spring-repository-1.0.xsd=org/springframework/data/repository/config/spring-repository-1.0.xsd
https\://www.springframework.org/schema/data/repository/spring-repository-1.4.xsd=org/springframework/data/repository/config/spring-repository-1.4.xsd
https\://www.springframework.org/schema/data/repository/spring-repository-1.5.xsd=org/springframework/data/repository/config/spring-repository-1.5.xsd
https\://www.springframework.org/schema/data/repository/spring-repository-1.6.xsd=org/springframework/data/repository/config/spring-repository-1.6.xsd
https\://www.springframework.org/schema/data/repository/spring-repository-1.7.xsd=org/springframework/data/repository/config/spring-repository-1.7.xsd
https\://www.springframework.org/schema/data/repository/spring-repository-1.8.xsd=org/springframework/data/repository/config/spring-repository-1.8.xsd
https\://www.springframework.org/schema/data/repository/spring-repository-1.11.xsd=org/springframework/data/repository/config/spring-repository-1.11.xsd
https\://www.springframework.org/schema/data/repository/spring-repository-2.1.xsd=org/springframework/data/repository/config/spring-repository-2.1.xsd
https\://www.springframework.org/schema/data/repository/spring-repository.xsd=org/springframework/data/repository/config/spring-repository-2.1.xsd
特殊情况
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:ldap="http://www.springframework.org/schema/ldap"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/ldap http://www.springframework.org/schema/ldap/spring-ldap.xsd">
<ldap:context-source id="contextSource"
url="xxx"
base="xxx"
username="xxx"
password="xxx"/>
<ldap:ldap-template id="ldapTemplate" context-source-ref="contextSource"/>
<context:component-scan base-package="xxx"/>
</beans>
如下加载appContext-ldap.xml时抛出异常,附加条件:网络不可达。
在 com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68) 在 com.intellij.rt.execution 的 org.junit.runner.JUnitCore.run(JUnitCore.java:137) 运行(SpringJUnit4ClassRunner.java:191) .junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47) at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242) at com.intellij.rt.execution.junit.JUnitStarter.main (JUnitStarter.java:70) 原因:org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException:来自类路径资源 [appContext-ldap-new.xml] 的 XML 文档中的第 673 行无效;嵌套异常是 org.xml.sax.SAXParseException;系统标识:startRunnerWithArgs(JUnit4IdeaTestRunner.java:68) at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47) at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java: 242)在 com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70) 引起:org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException:来自类路径资源的 XML 文档中的第 673 行 [appContext- ldap-new.xml] 无效;嵌套异常是 org.xml.sax.SAXParseException;系统标识:startRunnerWithArgs(JUnit4IdeaTestRunner.java:68) at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47) at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java: 242)在 com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70) 引起:org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException:来自类路径资源的 XML 文档中的第 673 行 [appContext- ldap-new.xml] 无效;嵌套异常是 org.xml.sax.SAXParseException;系统标识:JUnitStarter.main(JUnitStarter.java:70) 原因:org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException:来自类路径资源 [appContext-ldap-new.xml] 的 XML 文档中的第 673 行无效;嵌套异常是 org.xml.sax.SAXParseException;系统标识:JUnitStarter.main(JUnitStarter.java:70) 原因:org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException:来自类路径资源 [appContext-ldap-new.xml] 的 XML 文档中的第 673 行无效;嵌套异常是 org.xml.sax.SAXParseException;系统标识:http://www.springframework.org/schema/ldap/spring-ldap.xsd; 行号:673;列号:62;src-resolve: 无法将名称 'repository:repositories' 解析为 'type definition' 组件。 at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:399) at org.springframework.beans.factory xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:336) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:304) at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader. java:181) 在 org.springframework.beans.factory.support.AbstractBeanDefinitionReader.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:217) 在 org.springframework.beans.factory.support.AbstractBeanDefinitionReader。loadContext(AbstractDelegatingSmartContextLoader.java:251) at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:98) at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:116) ... 24 更多原因:org.xml.sax.SAXParseException; 系统标识:http://www.springframework.org/schema/ldap/spring-ldap.xsd; 行号:673;列号:62;src-resolve: 无法将名称 'repository:repositories' 解析为 'type definition' 组件。 at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:203) at com.sun org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:134) 在 com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:396) 在 com.sun。 org.apache.xerces.internal.impl.xs.traversers.XSDHandler.reportSchemaErr(XSDHandler.java:4154) 在 com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.reportSchemaError(XSDHandler.java :4137) 在 com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.getGlobalDecl(XSDHandler.java:1684) 在 com.sun.org.apache.xerces.internal.impl.xs.traversers .
我认为 Mybe 是 spring-ldap 的错误:
spring-ldap-2.2.xsd 中定义的 spring-repository.xsd schemaLocation 为
http://www.springframework.org/schema/data/repository/spring-repository.xsd
,但 schemaLocation 定义为https://www.springframework.org/schema/data/repository/spring-repository.xsd
spring-data-commons-2.1.10.RELEASE.jar 的 spring.schemas 中。一个是
http
,另一个是https
,不相同。
因此,当网络无法访问时,无法从本地找到 spring-repository.xsd。
github问题链接:https ://github.com/spring-projects/spring-ldap/issues/539