开发者社区> 问答> 正文

新手请教jfinal 使用ehcache的问题,Could not find c?报错

按照jfinal2文档的方法配置ehcache.

Config代码

@Override
	public void configPlugin(Plugins plugins) {
...
		plugins.add(new EhCachePlugin());
...
}



action如下

@Before(CacheInterceptor.class)
	@CacheName("columnList")
	public void index() {
		setAttr("xsPage", Column.dao.findAll());
		setAttr("title", OBJECTNAME + "列表");
...
		render(INDEXPAGE);
	}



<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="ehcache.xsd"
         updateCheck="false" monitoring="autodetect"
         dynamicConfig="true">

    <diskStore path="java.io.tmpdir"/>

    <defaultCache
           maxEntriesLocalHeap="10000"
           eternal="false"
           overflowToDisk="true"
           timeToIdleSeconds="20"
           timeToLiveSeconds="60">
    </defaultCache>
            
    <cache name="columnList"
           maxElementsInMemory="50"
           maxElementsOnDisk="100"
           eternal="false"
           timeToIdleSeconds="3600"
           timeToLiveSeconds="0"
           overflowToDisk="true"
           diskPersistent="true"
            />

</ehcache>



ehcache.xml

运行时,访问action就报错:

九月 04, 2015 9:04:54 下午 com.jfinal.plugin.ehcache.CacheKit warn
警告: Could not find cache config [columnList], using default.
九月 04, 2015 9:04:54 下午 com.jfinal.core.ActionHandler error
严重: /cms/column
net.sf.ehcache.CacheException: Caches cannot be added by name when default cache config is not specified in the config. Please add a default cache config in the configuration.
	at net.sf.ehcache.CacheManager.addCacheIfAbsent(CacheManager.java:1959)
	at com.jfinal.plugin.ehcache.CacheKit.getOrAddCache(CacheKit.java:48)
	at com.jfinal.plugin.ehcache.CacheKit.get(CacheKit.java:63)
	at com.jfinal.plugin.ehcache.CacheInterceptor.intercept(CacheInterceptor.java:55)
	at com.jfinal.aop.Invocation.invoke(Invocation.java:65)



即使删除 ehcache.xml也是这个错误,看来和配置文件无关,实在找不到原因了(我还禁用了shiro和相关插件,也似乎没关系),请高手指教

展开
收起
爱吃鱼的程序员 2020-06-12 14:07:15 721 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    me.add(newEhCachePlugin(PathKit.getRootClassPath() +"\\ehcache-shiro.xml"));

    shirocache配置文件读取,好像说是用新版本的cache-core才会有这个问题,如果是系统自带的Ehcache版本不会有这个问题

    plugins.add(newEhCachePlugin(PathKit.getRootClassPath()+" ehcache.xml"));

    是因为找不到配置文件引起的,修改成指定文件名就没有问题了

    引用来自“iginx”的评论

    plugins.add(newEhCachePlugin(PathKit.getRootClassPath()+" ehcache.xml"));

    是因为找不到配置文件引起的,修改成指定文件名就没有问题了

    这个是在Classes目录下,文件必须在这个目录下


    如果在web-inf下,还是要修改目录参数

    引用来自“iginx”的评论

    这个是在Classes目录下,文件必须在这个目录下


    如果在web-inf下,还是要修改目录参数

    引用来自“iginx”的评论

    me.add(newEhCachePlugin(PathKit.getRootClassPath() +"\\ehcache-shiro.xml"));

    shirocache配置文件读取,好像说是用新版本的cache-core才会有这个问题,如果是系统自带的Ehcache版本不会有这个问题

    JFinal自带的lib包里的Ehcache

    谢谢,我把maven配置的ehcache去掉就没报错了

    2020-06-12 14:07:34
    赞同 展开评论 打赏
问答标签:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
Java Spring Boot开发实战系列课程【第6讲】:Spring Boot 2.0实战MyBatis与优化(Java面试题) 立即下载
Java Spring Boot开发实战系列课程【第15讲】:Spring Boot 2.0 API与Spring REST Docs实战 立即下载
Java Spring Boot开发实战系列课程【第7讲】:Spring Boot 2.0安全机制与MVC身份验证实战(Java面试题) 立即下载