【问题标题】:How to Configure Eclipse to Work with `ehcache`如何配置 Eclipse 以使用 `ehcache`
【发布时间】:2017-12-18 21:08:48
【问题描述】:

总结/问题

我参与了一个使用ehcache 的项目。该项目已启用 maven,当我从 cli 运行 mvn clean install 时,一切都很好。

该项目也可以在 NetBeans 中打开,并且一切正常显示,但是当我在 eclipse 中打开该项目时,我看到一些与 ehcache 相关的错误。在 NetBeans 中,spring-cache.xml 位于“Web Pages”文件夹下。这让我觉得 eclipse 项目可能不被识别为动态 Web 项目,但是按照这里的指示:https://www.mkyong.com/java/how-to-convert-java-project-to-web-project-in-eclipse/ 我能够验证该项目确实设置为支持动态 Web 模块、Java 和 JavaScript。

我还在 IntelliJ 中打开了该项目,也没有发现 spring-cache.xml 有任何问题。

我也没有在http://www.ehcache.org/documentation/ 上找到与此版本的 ehcache 相关的文档,但是在 NetBeans、IntelliJ 和通过mvn clean install 中工作的事实让我认为这是我的 Eclipse 设置。想法?

更多详情:

我在eclipse中看到的错误是:

Multiple annotations found at this line:
- cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'ehcache:annotation-driven'.
- schema_reference.4: Failed to read schema document 'http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring-1.1.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>.

cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'ehcache:config'.

我的 maven 依赖如下:

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

哪个匹配它应该是什么,基于:https://mvnrepository.com/artifact/com.googlecode.ehcache-spring-annotations/ehcache-spring-annotations/1.2.0

我的 spring-cache.xml 文件看起来像:

<?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: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
                http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring 
                http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring/ehcache-spring-1.1.xsd">

    <ehcache:annotation-driven />
    <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="${ehcache.config.location}"/>
    </bean>

</beans>

【问题讨论】:

    标签: spring eclipse maven ehcache


    【解决方案1】:

    看起来当前版本的 NetBeans 和 IntelliJ 在检查方面不像 eclipse 那样严格。 :) 以下是我发现的。

    ehcache with Spring. google code xsd file not found我发现最上面的错误与xsd不再托管在提供的url上有关。

    做了一些谷歌,我在 github 上找到了对版本的引用:https://raw.githubusercontent.com/agentgt/ehcache-spring-annotations/master/core/src/main/resources/com/googlecode/ehcache/annotations/ehcache-spring-1.2.xsd 通过将我的底部 xsi 架构位置更改为上面的 url,它解决了 eclipse 中的问题。

    所引用的栈溢出问题,还提供了google代码存档的链接:https://code.google.com/archive/p/ehcache-spring-annotations/source/default/source

    如果你下载了 zip,你可以在 zip 中找到官方 xsd:/schema/ehcache-spring/ehcache-spring-1.2.xsd(它也有 ehcache-spring-1.0.xsdehcache-spring1.1.xsd,以防其他人对更早的版本有问题)。

    我在这里找到了一种引用本地架构文件的方法:How to reference a local XML Schema file correctly?

    我将发布一个关于如何从项目的相对路径中引用它的问题,因为我们在这个项目中有 windows 和 mac 开发人员。如果这对您有用,详细信息将在这里:How to Reference Local XSD File By Relative Path

    【讨论】:

      【解决方案2】:

      问题摘要:

      xsi-schema位置参考:

      http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring/ehcache-spring-1.1.xsd

      在 Eclipse 中导致验证问题,在命令行 maven 上没有问题。

      将 ref 替换为:

      https://raw.githubusercontent.com/agentgt/ehcache-spring-annotations/master/core/src/main/resources/com/googlecode/ehcache/annotations/ehcache-spring-1.1.xsd

      解决了eclipse中的问题。但是,在 Maven 中,如果您没有连接到互联网,saxparser 会抱怨。 通过放置代理 ref : -Dhttp.proxyHost=[代理主机] -Dhttp.proxyPort=[代理端口] -Dhttps.proxyHost=[代理主机] -Dhttps.proxyPort=[代理端口] maven 构建成功....

      我调查了这种行为差异: 在 ehcache-spring jar 中,ehcache-spring-annotations-1.1.2.jar, 存在一个 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

      cmdline maven 使用此内容(并在 jar 中找到 xsd)。 日食没有。

      我使用的解决方案: 转到日食偏好, XML -> XML Catalog 并添加一个新的用户条目:

      位置:https://raw.githubusercontent.com/agentgt/ehcache-spring-annotations/master/core/src/main/resources/com/googlecode/ehcache/annotations/ehcache-spring-1.1.xsd

      密钥类型:公共ID

      密钥:http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring/ehcache-spring-1.1.xsd

      备用网址:https://raw.githubusercontent.com/agentgt/ehcache-spring-annotations/master/core/src/main/resources/com/googlecode/ehcache/annotations/ehcache-spring-1.1.xsd

      重新验证 spring 上下文文件解决了我的 eclipse 工作区中的问题。

      我更喜欢这个解决方案,因为它是 eclipse 的一个缺点,我使用 eclipse 特定的解决方案来解决。

      【讨论】:

        猜你喜欢
        • 2023-03-10
        • 2014-12-25
        • 2017-08-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-11
        • 1970-01-01
        • 2012-07-22
        相关资源
        最近更新 更多