我想在 applicationContext.xml 中使用个人命名空间。 我用的是Spring3。
所以,在我的 appliationContext 中,在 beans 标记中我有:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:profile="http://icfi.com/springbeans/profile"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd
http://icfi.com/springbeans/profile http://icfi.com/springbeans/profile/profile.xsd">
这里重要的一行是
http://icfi.com/springbeans/profile http://icfi.com/springbeans/profile/profile.xsd
我说我想使用profile.xsd。显然,这个文件不在线,但我的 META-INF 文件夹中有一个 spring.schemas 文件:
http\://icfi.com/springbeans/profile/profile.xsd=profile.xsd
在里面。
我的本地 profile.xsd 文件位于 src/main/resources 中。
我的问题是在 Eclipse 中,它说找不到 xsd。如果我给他我文件的绝对路径:
file:///c:/[...]/project/src/main/resources/profile.xsd
问题是一样的 然后我只给他“profile.xsd”,整行变成:
http://icfi.com/springbeans/profile profile.xsd
这里 Eclipse 可以读取它!万岁?并不是真的因为: 它没有读取我的 spring.schemas,因为我必须提供文件的真实(相对)路径,更重要的是,当我启动我的应用程序时,在每种情况下(使用 spring.schema 的 url,使用完整路径或相对路径)我总是:
org.xml.sax.SAXParseException: schema_reference.4: Failed to read schema document 'profile.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>.
at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source) ~[xercesImpl-2.9.1.jar:?]
我认为我的 profile.xsd 很好,因为我可以让 eclipse 读取它,但为了以防万一,这是我的文件:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns="http://icfi.com/springbeans/profile"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:beans="http://www.springframework.org/schema/beans"
targetNamespace="http://icfi.com/springbeans/profile"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xsd:element name="if">
<xsd:complexType>
<xsd:sequence>
<xsd:any minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="test" type="xsd:string" use="required" />
<xsd:attribute name="src" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
我真的不明白为什么:
- 我无法将“http://icfi.com/springbeans/profile/profile.xsd”绑定(bind)到我的 profile.xsd
- 我无法读取 profile.xsd,即使 eclipse 说它可以读取它并且没关系。
你能帮我找到解决方案吗?
最诚挚的问候
最佳答案
我已经找到解决办法了。我将我的命名空间哈德勒和解析器导出到外部 jar,它工作正常。 为了绑定(bind),我已经在网上上传了xsd。
现在一切正常了:)
关于java - Spring:xsi:schemaLocation无法从spring.schemas读取配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31295034/