2011-10-17 105 views
1

我正在嘗試配置一個Spring配置(xml)文件,並且試圖爲我在本地項目中本地生存的有效模式文件添加命名空間。原因是,我沒有「真正的」 URL(Web服務器等),所以我想只使用本地模式,我將WEB-INF/下提供:Spring XML配置和命名空間

MyProject/ 
    src/ 
     java/ 
     config/ 
      MySchema.xsd 
      spring-config.xml 
    build.xml 

裏面我spring-config.xml

<?xml version="1.0" encoding="UTF-8"?> 

<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:ms="http://myproject.org/MySchema.xsd" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation=" 
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd 
    http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd"> 

項目是建設&部署很好,但是當我去運行它,我得到:

org.xml.sax.SAXException: Failed to locate XSD resource '/META-INF/MySchema.xsd' on 
classpath. Namespace: 'http://myproject.org/MySchema.xsd'. 

最後,我想這兩個spring-config.xmlMySchema.xsd存儲在WEB-INF/,所以我不知道爲什麼春天正在尋找內部META-INF/ ...任何想法?

URL http://myproject.org/MySchema.xsd不是一個真正的URL,只是給架構自己的命名空間。提前致謝!

+1

這就是SAX尋找'META-INF'中的xsd,而不是Spring。 –

回答

2

在xsi:schemaLocation屬性中沒有「定義」(我不知道正確的術語)http://myproject.org/MySchema.xsd。嘗試是這樣的:

xsi:schemaLocation=" 
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd 
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd 
http://myproject.org/MySchema.xsd location/of/MySchema.xsd"> 
+0

謝謝@DwB! – IAmYourFaja

0

您還需要定義schema locationhttp://myproject.org/MySchema.xsdnamespace。從W3C開始,模式位置:

由一對或多對URI引用組成,由空格分隔。每對中的第一個成員是一個名稱空間名稱,而該對的第二個成員是一個提示,描述了爲該名稱空間查找適當模式文檔的位置。這些提示的存在並不要求處理器獲得或使用引用的模式文檔,並且處理器可以自由地使用通過任何適當手段獲得的其他模式,或根本不使用模式。

我會使用不同的名稱空間名稱,以免與名稱空間模式文檔提示混淆。也許可以使用模式位置,例如http://myproject.org/my-schema config/MySchema.xsd