`
足至迹留
  • 浏览: 486726 次
  • 性别: Icon_minigender_1
  • 来自: OnePiece
社区版块
存档分类
最新评论

<ehcache-1> SelfPopulatingCacheScope异常

阅读更多
环境配置:
1.版本配置:
spring 3.0.5 Release + ehcache-spring-annotations-1.1.2 + tomcat6 (+ tuscany2.0.1 tuscany 对缓存配置不知有无影响。)
因为使用的spring是3.1之前版本,spring在2.5之后删除原生配置ehcache后还没添加新的支持ehcache,所以使用了ehcache-spring-annotations-1.1.2,spring3.1之后可以使用自己的ehcache支持。

2.配置文件:
application-context.xml
<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:util="http://www.springframework.org/schema/util"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:ehcache="http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring"
       xmlns:p="http://www.springframework.org/schema/p"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
       http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
       http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
       http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-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">
    <context:property-placeholder properties-ref="jdbc"/>
    <ehcache:annotation-driven cache-manager="ehCacheManager"/>
    <bean id="ehCacheManager" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
        <property name="configLocation" value="classpath:ehcache.xml" />
    </bean> 
......


ehcache.xml
<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd"
         updateCheck="false" monitoring="autodetect">
    <diskStore path="java.io.tmpdir" />
    <defaultCache eternal="true" maxElementsInMemory="100" overflowToDisk="false" />
    <cache name="userCache"
	       maxElementsInMemory="200"
	       timeToIdleSeconds="120"
		   timeToLiveSeconds="600"
		   eternal="false"
		   overflowToDisk="false"
		   maxElementsOnDisk="0"
		   diskPersistent="false"
		   diskExpiryThreadIntervalSeconds="0"
		   memoryStoreEvictionPolicy="LRU">
    </cache>
</ehcache>


异常信息:



分析解决:
no enum const class com.googlecode.ehcache.annotations.SelfPopulatingCacheScope.
看报错是枚举常量不存在。这个是Enum类调用valueOf()方法抛出的异常,查看jdk源码:
public static <T extends Enum<T>> T valueOf(Class<T> enumType,
                                                String name) {
        T result = enumType.enumConstantDirectory().get(name);
        if (result != null)
            return result;
        if (name == null)
            throw new NullPointerException("Name is null");
        throw new IllegalArgumentException(
            "No enum const " + enumType +"." + name);
    }

说明是使用SelfPopulatingCacheScope时没有指定有效的枚举常量。
查找官网http://code.google.com/p/ehcache-spring-annotations/配置说明,在http://code.google.com/p/ehcache-spring-annotations/wiki/UsingCacheable找到开始查找SelfPopulatingCacheScope的配置:



但这个配置是有默认值的,所以刚开始觉得不是这个问题,以为是缺少其他包或配置错误,没有解决。后来转了一圈还是把这个配置配上去了,配成:<ehcache:annotation-driven cache-manager="ehCacheManager" self-populating-cache-scope="shared"/>结果就好了。
奇怪的是默认值为啥没起作用,因为项目使用了soa的框架tuscany,spring的配置被Tuscany代理了,所以不知跟tuscany有关。

补充说明:
另外还有一点说明,项目没用springMVC,所以用ehcache-spring-annotations-1.1.2还必须使用spring-context-support(如果是maven配置的话,如果构建使用的ant就直接下载把添加依赖就可以了):
<dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context-support</artifactId>
            <version>3.0.3.RELEASE</version>
        </dependency>

否则启动也报错,报错“beanName”ehCacheManager is null。如果使用springMVC 3.0.*版本,则不需要单独配置spring-context-support,因为springMVC已经内置这个依赖了。
至此,这个问题算是解决了。
  • 大小: 340.5 KB
  • 大小: 219.5 KB
0
2
分享到:
评论

相关推荐

    ehcache监控工具ehcache-monitor-kit-1.0.3

    1.解压缩到目录下,复制ehcache-monitor-kit-1.0.0\lib\ehcache-probe-1.0.0.jar包到application的web-inf/lib目录下 2.将以下配置copy的ehcache.xml文件的ehcache标签中,注:上述链接中说的配置少写了个probe包名...

    ehcache-3.9.9-API文档-中英对照版.zip

    赠送jar包:ehcache-3.9.9.jar; 赠送原API文档:ehcache-3.9.9-javadoc.jar; 赠送源代码:ehcache-3.9.9-sources.jar; 赠送Maven依赖信息文件:ehcache-3.9.9.pom; 包含翻译后的API文档:ehcache-3.9.9-javadoc-...

    shiro-ehcache-1.4.0-API文档-中文版.zip

    赠送jar包:shiro-ehcache-1.4.0.jar; 赠送原API文档:shiro-ehcache-1.4.0-javadoc.jar; 赠送源代码:shiro-ehcache-1.4.0-sources.jar; 赠送Maven依赖信息文件:shiro-ehcache-1.4.0.pom; 包含翻译后的API文档...

    ehcache-3.3.1-API文档-中英对照版.zip

    赠送jar包:ehcache-3.3.1.jar; 赠送原API文档:ehcache-3.3.1-javadoc.jar; 赠送源代码:ehcache-3.3.1-sources.jar; 赠送Maven依赖信息文件:ehcache-3.3.1.pom; 包含翻译后的API文档:ehcache-3.3.1-javadoc-...

    ehcache-web-2.0.4-API文档-中文版.zip

    赠送jar包:ehcache-web-2.0.4.jar; 赠送原API文档:ehcache-web-2.0.4-javadoc.jar; 赠送源代码:ehcache-web-2.0.4-sources.jar; 赠送Maven依赖信息文件:ehcache-web-2.0.4.pom; 包含翻译后的API文档:...

    ehcache-core-2.6.11-API文档-中文版.zip

    赠送jar包:ehcache-core-2.6.11.jar; 赠送原API文档:ehcache-core-2.6.11-javadoc.jar; 赠送源代码:ehcache-core-2.6.11-sources.jar; 赠送Maven依赖信息文件:ehcache-core-2.6.11.pom; 包含翻译后的API文档...

    ehcache.rar ehcache-core-2.6.10.jar依赖包

    ehcache-core-2.6.10.jar依赖包 MyBatiesEhCache二级缓存 Ehcache是一种广泛使用的开源Java分布式缓存。主要面向通用缓存,Java EE和轻量级容器。它具有内存和磁盘存储,缓存加载器,缓存扩展,缓存异常处理程序,一个...

    ehcache 缓存

    <ehcache>  <diskStore path="java.io.tmpdir"/>  <defaultCache  maxElementsInMemory="10000" <!-- 缓存最大数目 -->  eternal="false" <!-- 缓存是否持久 -->  overflowToDisk="true" <!-- 是否...

    JavaEE源代码 ehcache-1.1

    JavaEE源代码 ehcache-1.1JavaEE源代码 ehcache-1.1JavaEE源代码 ehcache-1.1JavaEE源代码 ehcache-1.1JavaEE源代码 ehcache-1.1JavaEE源代码 ehcache-1.1JavaEE源代码 ehcache-1.1JavaEE源代码 ehcache-1.1JavaEE源...

    SpringShiro分布式缓存版

    &lt;property name="cacheManagerConfigFile" value="classpath:ehcache-shiro.xml" /&gt; &lt;/bean&gt; 添加了redis缓存... &lt;!-- 缓存相关配置 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!...

    ehcache缓存jar(ehcache-core-2.4.6.jar+ehcache-web-2.0.4.jar)

    ehcache缓存jar(ehcache-core-2.4.6.jar+ehcache-web-2.0.4.jar)

    ehcache-core-2.6.11.jar

    含有 三个版本:ehcache-core-2.6.11 ;ehcache-core-2.6.9;ehcache-core-2.5.0

    ehcahe页面缓存详细内容

    1.需要将附件中2个jar放入lib中 2.将ehcache.xml放入能加载到classpath中的任意包中,不能放入WEB-INF中(其详细配置参数代表含义已经注释) 3.在工程中web.xml配置过滤器 &lt;filter&gt; &lt;filter-name&gt;...

    Ehcache 3(ehcache-clustered-3.8.1-kit.zip)

    具有集群支持的 Ehcache 3(ehcache-clustered-3.8.1-kit.zip)

    简单配置 shiro + spring +springMVC+hibernate简单框架

    &lt;artifactId&gt;ehcache-core&lt;/artifactId&gt; &lt;version&gt;2.5.3&lt;/version&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;org.slf4j&lt;/groupId&gt; &lt;artifactId&gt;slf4j-jdk14&lt;/artifactId&gt; &lt;version&gt;1.6.4&lt;/version&gt; &lt;/...

    ehcache-core-2.5.1.jar

    ehcache-core-2.5.1.jar

    ehcache-core-2.6.5.jar和mybatis-ehcache-1.0.2.jar

    ehcache.xml配置内容 &lt;ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.ehcache.org/ehcache.xsd"&gt; &lt;diskStore path="java.io.tmpdir"/&gt; ...&lt;/ehcache&gt;

    hibernate-ehcache-4.3.9.Final.jar

    该包是hibernate中所用的一个包,专门用来去处理特定的问题,它是和ehcache一起用的一个包

    ehcache-core-2.6.10.jar

    ehcache-core-2.6.10.jar专用包,欢迎下载 ehcache-core-2.6.10.jar ehcache-core-2.6.10.jar ehcache-core-2.6.10.jarehcache-core-2.6.10.jarehcache-core-2.6.10.jar

    ehcache-core-2.5.0.jar

    jar包,官方版本,自测可用

Global site tag (gtag.js) - Google Analytics