2012-11-07 28 views
6

當我們將ehcache.xml中的XSD文件指向http://ehcache.org/ehcache.xsd時,我們正面臨有關EhCache和Spring的一個問題,一切正常,我們的應用程序可以啓動正確。 但我們的服務器無法訪問外部網站,所以我們將XSD位置更改爲本地,如下所示,但應用程序無法啓動,出現以下異常(已將ehcache.xsd複製到classes文件夾,與ehcache.xml相同)。 我已經使用了許多解決方案,但它仍然無法修復。我需要你的幫助。非常感謝你。如何在Spring中使用本地xsd進行EhCache

春:3.1.0 的Ehcache:2.4.2 服務器:Tomcat的6.0 的Java:1.6

配置:

<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:noNamespaceSchemaLocation="ehcache.xsd" 
    updateCheck="false" monitoring="autodetect" dynamicConfig="true"> 

例外:

2012-11-07 16:54:42,003 WARN [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] - <Ignored XML validation warning> 
org.xml.sax.SAXParseException: schema_reference.4: Failed to read schema document 'ehcache.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 com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:195) 
    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.warning(ErrorHandlerWrapper.java:96) 
    at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:380) 
    at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:318) 
    at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.findSchemaGrammar(XMLSchemaValidator.java:2440) 
    ... more 
2012-11-07 16:54:42,007 ERROR [org.springframework.web.context.ContextLoader] - <Context initialization failed> 
org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 3 in XML document from ServletContext resource [/WEB-INF/classes/META-INF/ehcache.xml] is invalid; nested exception is org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'ehcache'. 
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:396) 
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334) 
    ... more 
Caused by: org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'ehcache'. 
    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:195) 
    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:131) 

    ... more 
+0

http://www.ehcache.org/ehcache.xsd – OhadR

回答

1

我的解決方法是增加這個xsd文件改爲絕對路徑,例如:c:/ehcache.xsd並指向ehcache.xml中的這個位置。 希望這會幫助面臨同樣問題的人。

仍然期待找到其他解決方案。

謝謝。

7

通常我設置xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd",但這不能在離線環境下工作。

9

下載ehcache.xsd,把它放到你的config xml文件所在的同一個文件夾中。 修改XML頭像下面,注意類路徑前綴:

<ehcache 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:noNamespaceSchemaLocation="classpath:ehcache.xsd"> 

這將在開發和生產環境中工作。

+0

即使在沒有'classpath:'前綴的情況下,如果在同一個目錄下,它甚至可以工作。 thnks – msangel

相關問題