spring - 如何通过 Spring 将本地 xsd 用于 EhCache

标签 spring ehcache

当我们将 ehcache.xml 中的 XSD 文件指向 http://ehcache.org/ehcache.xsd 时,我们遇到了一个关于 EhCache 和 Spring 的问题。 ,一切正常,我们的应用程序可以正确启动。 但是我们的服务器无法访问外部网站,因此我们将 XSD 位置更改为本地,如下所示,但应用程序无法启动,并出现以下异常(已将 ehcache.xsd 复制到类文件夹,与 ehcache.xml 相同)。 我用谷歌搜索了很多解决方案,但仍然无法修复。我需要你的帮助。非常感谢。

Spring :3.1.0 埃缓存: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"> 

异常(exception):

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

最佳答案

下载ehcache.xsd ,将其放入配置 xml 文件所在的同一文件夹中。 修改 xml 头如下,注意 classpath 前缀:

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

这将在开发和生产环境中工作。

关于spring - 如何通过 Spring 将本地 xsd 用于 EhCache,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13266339/

相关文章:

java - 如何实例化 ehcache.CacheEventListener?

java - Ehcache午夜/夜间过期策略

java - Spring Boot 和 Jersey 产生 ClassNotFound

java - 限制每个资源的最大文件大小

java - 在 Spring Cloud 应用程序中实现重试

java - 服务器启动时由于 ecache 请求负载过多而导致数据库服务器停止运行

java - Jackson动态Pojo<T>反序列化

java - 我们什么时候应该在 Spring 中使用@Component?

java - 插入新记录时 hibernate 缓存查询未更新

java - 缓存整个表