如何配置Eclipse以使用`ehcache` [英] How to Configure Eclipse to Work with `ehcache`
问题描述
摘要/问题
我已经滚到使用 ehcache的项目
。该项目启用了maven,当我运行 mvn clean install
从cli全部结束。
该项目也可以在NetBeans中打开,一切正常显示,但是当我在eclipse中打开项目时,我看到一些与 ehcache的
。在NetBeans中,spring-cache.xml位于Web Pages文件夹下。这使我认为,eclipse项目可能不被认为是一个动态的Web项目,但遵循以下指导:
和
cvc-complex-type.2.4.c:匹配的通配符是严格的,但没有声明可以找到元素'ehcache:config'。
我的maven依赖关系看起来像:
< dependency>
< groupId> com.googlecode.ehcache-spring-annotations< / groupId>
< artifactId> ehcache-spring-annotations< / artifactId>
< version> 1.2.0< / version>
< / dependency>
我的spring-cache.xml文件如下所示:
<?xml version =1.0encoding =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:注释驱动/>
< ehcache:config cache-manager =cacheManager>
< ehcache:evict-expired-elements interval =60/>
< / ehcache:config>
< bean id =cacheManagerclass =org.springframework.cache.ehcache.EhCacheManagerFactoryBean>
< property name =configLocationvalue =$ {ehcache.config.location}/>
< / bean>
< / beans>
看起来像当前版本的NetBeans和IntelliJ像eclipse那样严格检查。 :)以下是我发现的。
从 ehcache与Spring。谷歌代码xsd文件未找到我发现最高的错误是与xsd不再托管在提供的URL相关的事实。
做一些Google搜索引擎,我在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中的问题。
堆栈溢出问题引用,还提供了一个链接到谷歌代码归档文件: 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.xsd
和 ehcache-spring1.1.xsd
如果任何人有更早版本的问题)。
我在这里找到了一种引用本地架构文件的方法:如何正确引用本地XML Schema文件?
我要发布问题关于如何从项目的相对路径引用它,因为我们有这个项目的windows和mac开发人员。如果这对您有用,详细信息将在此处:如何通过相对路径参考本地XSD文件
Summary/Question
I've rolled onto a project that uses ehcache
. The project is maven enabled and when I run mvn clean install
from cli all ends well.
The project can also be opened in NetBeans and everything displays properly, however when I open the project in eclipse, I'm seeing some errors related to ehcache
. In NetBeans the spring-cache.xml is located under a "Web Pages" folder. This made me think that the eclipse project may not be recognized as a dynamic web project, however following the directions here: https://www.mkyong.com/java/how-to-convert-java-project-to-web-project-in-eclipse/ I was able to verify that the project is indeed setup to support Dynamic Web Module, Java and JavaScript.
I also opened the project in IntelliJ and also did not see any issues with the spring-cache.xml.
I also didn't find documentation related to this version of ehcache on http://www.ehcache.org/documentation/ but the fact that things work in NetBeans, IntelliJ and via mvn clean install
make me think its my eclipse setup. Thoughts?
More Details:
The errors I see in eclipse are:
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>.
And
cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'ehcache:config'.
My maven dependency looks like:
<dependency>
<groupId>com.googlecode.ehcache-spring-annotations</groupId>
<artifactId>ehcache-spring-annotations</artifactId>
<version>1.2.0</version>
</dependency>
Which matches what it should be, based on: https://mvnrepository.com/artifact/com.googlecode.ehcache-spring-annotations/ehcache-spring-annotations/1.2.0
My spring-cache.xml file looks like:
<?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>
Looks like current versions of NetBeans and IntelliJ aren't as strict on checking things as eclipse is. :) The following is what I found out.
From ehcache with Spring. google code xsd file not found I found out that the top error was related to the fact that the xsd is no longer hosted at the url provided.
Doing some googles, I found a reference to the version on github at: https://raw.githubusercontent.com/agentgt/ehcache-spring-annotations/master/core/src/main/resources/com/googlecode/ehcache/annotations/ehcache-spring-1.2.xsd by changing my bottom xsi schemalocation to the above url, it resolved the issue in eclipse.
The stack overflow questions referenced, also provides a link to the google code archive of: https://code.google.com/archive/p/ehcache-spring-annotations/source/default/source
If you download the zip, you can then find the offical xsd in the zip at: /schema/ehcache-spring/ehcache-spring-1.2.xsd
(it also has ehcache-spring-1.0.xsd
and ehcache-spring1.1.xsd
in case anyone else has issues with even earlier versions).
I found a way to reference the local schema file here: How to reference a local XML Schema file correctly?
I'm going to post a question on how to reference it from a relative path of the project, as we have both windows and mac developers on this project. If this is of use to you, the details will be here: How to Reference Local XSD File By Relative Path
这篇关于如何配置Eclipse以使用`ehcache`的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!