Java Spring:xsi:schemaLocation可以';t从spring.schemas读取配置

Java Spring:xsi:schemaLocation可以';t从spring.schemas读取配置,java,xml,eclipse,spring,xsd,Java,Xml,Eclipse,Spring,Xsd,我想在applicationContext.xml中使用个人名称空间。 我正在使用Spring3 因此,在我的应用程序上下文中,在beans标记中我有: <beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:util="http://www.springframework.org/schema

我想在applicationContext.xml中使用个人名称空间。 我正在使用Spring3

因此,在我的应用程序上下文中,在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">
在里面

我的本地profile.xsd文件位于src/main/resources中

我的问题是,在eclipse中,它说它找不到xsd。我给他我的文件的绝对路径:

<?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>
file:///c:/[…]/project/src/main/resources/profile.xsd

问题是一样的 然后我只给他“profile.xsd”,整行变成:

http://icfi.com/springbeans/profile profile.xsd

在这里Eclipse可以阅读它!万岁?不是因为: 它没有读取我的spring.schema,因为我必须给出文件的真实(相对)路径,更重要的是,当我启动应用程序时,在任何情况下(使用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:?]
org.xml.sax.SAXParseException:schema_reference.4:无法读取架构文档'profile.xsd',因为1)找不到该文档;2) 文件无法读取;3) 文档的根元素不是。
在org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(未知源)~[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“到my profile.xsd
  • 我无法阅读profile.xsd,即使eclipses说它可以阅读,而且还可以
你能帮我找到解决办法吗


最诚挚的问候

我找到了解决办法。我将我的namespaceHadler和解析器导出到一个外部jar,它工作得很好。 对于绑定,我已经在线上传了xsd


现在它运行良好:)

我找到了一个解决方案。我将我的namespaceHadler和解析器导出到一个外部jar,它工作得很好。 对于绑定,我已经在线上传了xsd

现在它工作正常:)