【问题标题】:"ehcache: annotation-driven" definition cannot be found in my Spring context file在我的 Spring 上下文文件中找不到“ehcache:注释驱动”定义
【发布时间】:2014-03-06 16:30:46
【问题描述】:

我有一个使用 Spring 和 Ehcache 的应用程序。每次我从 Eclipse 启动应用程序时,它都运行良好。但是当我从 Maven 构建它并在服务器上运行它时,我一直有这个错误:

    INFO  XmlBeanDefinitionReader - Loading XML bean definitions from class path resource [spring.xml]
    Exception in thread "main"     org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 29 in XML document from class path
resource [spring.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 29; columnNumber: 71; cvc-complex-type.2.
4.c: The matching wildcard is strict, but no declaration can be found for element 'ehcache:annotation-driven'.
        at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:398)
        at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:335)
        at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:303)
        at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180)
        at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:216)
        at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:187)
        at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:251)
        at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:127)
        at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:93)
        at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:129)
        at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:540)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:454)
        at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
        at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:93)
        at com.natixis.etp.data.rmi.DataServer.main_aroundBody0(DataServer.java:145)
        at com.natixis.etp.data.rmi.DataServer.main(DataServer.java:45)
Caused by: org.xml.sax.SAXParseException; lineNumber: 29; columnNumber: 71; cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'ehcache:annotation-driven'.
        at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
        at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source)
        at org.springframework.beans.factory.xml.DefaultDocumentLoader.loadDocument(DefaultDocumentLoader.java:76)
        at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadDocument(XmlBeanDefinitionReader.java:428)
        at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:390)

ehcache:annotation-driven 定义存在于 ehcache-spring-1.2.xsd 中。
我已经阅读了有关它的几个相关问题,我应用了建议的内容,但到目前为止我还没有运气。由于我们的环境细节,我不使用也不能使用 Maven 着色器插件,而且我认为它不会有帮助,因为我检查并重新检查了依赖项中的模式处理程序。

我想知道你是否有任何线索。这是我的弹簧文件:

        <?xml version="1.0" encoding="UTF-8"?>
        <beans xmlns="http://www.springframework.org/schema/beans"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
            xmlns:context="http://www.springframework.org/schema/context"
            xmlns:tx="http://www.springframework.org/schema/tx" 
            xmlns:aop="http://www.springframework.org/schema/aop"
            xmlns:ehcache="http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring"
            xsi:schemaLocation="
            http://www.springframework.org/schema/beans 
            http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
            classpath:spring-beans-3.0.xsd 
            http://www.springframework.org/schema/aop 
            http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
            classpath:spring-aop-3.0.xsd
            http://www.springframework.org/schema/context 
            http://www.springframework.org/schema/context/spring-context-3.2.xsd
            classpath:spring-context.xsd
            http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring
            http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring/ehcache-spring-1.2.xsd
            classpath:ehcache-spring-1.2.xsd
            ">

            <context:annotation-config />
            <context:spring-configured />

            [...]

            <ehcache:annotation-driven mode="aspectj"
                cache-manager="cacheManager" self-populating-cache-scope="shared" />

            <aop:aspectj-autoproxy>
                <aop:include name="traceInvocation" />
                <!-- aop:include name="performanceMonitor" / -->
                <aop:include name="ehCacheInvocation" />
            </aop:aspectj-autoproxy>

            <ehcache:config cache-manager="cacheManager">
                <ehcache:evict-expired-elements
                    interval="60" />
            </ehcache:config>

            <bean id="cacheManager"
                class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
                <property name="configLocation" value="META-INF/ehcache.xml" />
                <property name="shared" value="true" />
            </bean>
            [...]
        </beans> 

如您所见,我添加了类路径条目,因为我与 Spring aop 模式处理程序中的模式处理程序发生冲突。 我检查了ehcache-aspectj-annotations-1.2.0.jar.dir/META-INF/spring.schemas的内容:

http\://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring/ehcache-spring-1.0.xsd=com/googlecode/ehcache/annotations/ehcache-spring-1.0.xsd
http\://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring/ehcache-spring-1.1.xsd=com/googlecode/ehcache/annotations/ehcache-spring-1.1.xsd
http\://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring/ehcache-spring-1.2.xsd=com/googlecode/ehcache/annotations/ehcache-spring-1.2.xsd

我觉得很好。

顺便说一下,这是我的主要依赖项:

    <dependencies>
    [...]
        <dependency>
            <groupId>aopalliance</groupId>
            <artifactId>aopalliance</artifactId>
            <version>1.0</version>
        </dependency>
        <dependency>
            <groupId>xerces</groupId>
            <artifactId>xercesImpl</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context-support</artifactId>
        </dependency>
        <dependency>
            <groupId>net.sf.ehcache</groupId>
            <artifactId>ehcache-core</artifactId>
            <version>2.4.1</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>**************</groupId>
            <artifactId>ehcache-aspectj-annotations</artifactId>
            <version>1.2.0</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjrt</artifactId>
            <version>${aspectj.version}</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjweaver</artifactId>
            <version>${aspectj.version}</version>
        </dependency>

        <dependency>
          <groupId>com.googlecode.ehcache-spring-annotations</groupId>
          <artifactId>ehcache-spring-annotations</artifactId>
          <version>1.2.0</version>
        </dependency>
    </dependencies>

【问题讨论】:

  • 你是否在 maven pom 或 Eclipse 中添加了对 ehcache-annotations 的依赖?它需要是一个 Maven 依赖项
  • 是的,肖恩。我顺便添加了我的依赖项以使其更清晰。实际上,我的依赖项中有“ehcache-aspectj-annotations”,我没有“ehcache-annotations”,我会检查一下。
  • 肖恩,我添加了以下似乎需要但没有成功的依赖项:com.googlecode.ehcache-spring-annotationsehcache-spring -annotations1.2.0

标签: java spring maven annotations ehcache


【解决方案1】:

好的,我无法找到问题的根本原因,但我尝试使用 Spring bean 源代码来跟踪导致此问题的调用。 尽管我的项目在 Java 7 下,但我使用的 Spring bean 版本(4.0.2-RELEASE)似乎引用了 Java 8 类。

我不确定这是否是问题所在,因为我希望得到一个明确的错误消息,但无论如何,我回滚到 Spring bean 的 Java 7 兼容版本 (3.2.8.RELEASE) 并且问题消失了。现在它工作得很好,即使它有点令人沮丧。

【讨论】:

    【解决方案2】:

    我遇到了类似的问题,想补充一些细节,以防其他人正在搜索。错误:

    nested exception is org.xml.sax.SAXParseException; lineNumber: 29; columnNumber: 71; cvc-complex-type.2. 4.c: The matching wildcard is strict, but no declaration can be found for element 'ehcache:annotation-driven'.

    表示找不到ehcache:annotation-driven 的含义。这是因为不再托管 uri 上的 xsd 文件。我找到了该文件的存档版本并将其放在同一目录中,然后能够通过相对路径引用 xsd。

    更多详情,您可以阅读相关问题/答案:How to Configure Eclipse to Work with `ehcache`How to Reference Local XSD File By Relative PathContext.xml's References

    【讨论】:

      【解决方案3】:

      您的 XML 解析器正在尝试针对您的链接架构位置进行验证 - 并且“注释驱动”标签未出现在提供的架构中。不幸的是,我之前遇到过这个错误(也是间歇性的),也许这表明远程位置暂时关闭(您希望通过更明确的错误消息)

      【讨论】:

        猜你喜欢
        • 2014-02-09
        • 2012-11-11
        • 2015-03-11
        • 2013-04-05
        • 1970-01-01
        • 2017-10-13
        • 2017-08-15
        • 2017-06-10
        • 2013-09-21
        相关资源
        最近更新 更多