2012-11-07 25 views
6

Chúng ta đang đối mặt với một vấn đề về EhCache và Spring, khi chúng ta trỏ tệp XSD trong ehcache.xml đến http://ehcache.org/ehcache.xsd, mọi thứ đều ổn, ứng dụng của chúng ta có thể khởi động đúng. Nhưng máy chủ của chúng tôi không thể truy cập trang web bên ngoài, vì vậy chúng tôi đã thay đổi vị trí XSD thành địa phương như bên dưới, nhưng ứng dụng không thể khởi động với ngoại lệ sau (đã sao chép ehcache.xsd vào thư mục lớp học, giống như ehcache.xml). Tôi đã googled nhiều giải pháp, nhưng nó vẫn không thể được cố định. Tôi cần sự giúp đỡ của bạn về việc này. Cảm ơn nhiều.Cách sử dụng xsd cục bộ cho EhCache với Spring

mùa xuân: 3.1.0 ehcache: 2.4.2 Server: Tomcat 6.0 Java: 1.6

Config:

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

Ngoại lệ:

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

Trả lời

1

Cách giải quyết của tôi là thêm tệp xsd này vào đường dẫn tuyệt đối, chẳng hạn như: c: /ehcache.xsd và trỏ đến vị trí này trong tệp ehcache.xml. Hy vọng điều này sẽ giúp ai đó đối mặt với cùng một vấn đề.

Vẫn đang tìm kiếm giải pháp khác.

Cảm ơn.

7

thường tôi đặt xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd", nhưng điều này không thể hoạt động trong môi trường ngoại tuyến.

9

Tải xuống ehcache.xsd, đặt nó vào cùng thư mục chứa tệp cấu hình xml của bạn. sửa đổi người đứng đầu xml như dưới đây, chú ý classpath tiền tố:

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

này sẽ làm việc trong sự phát triển và sản xuất môi trường.

+0

thậm chí công việc này không có tiền tố 'classpath:', nếu trong cùng một thư mục. thnks – msangel

Các vấn đề liên quan