按照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>
运行时,访问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)
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。
me.add(newEhCachePlugin(PathKit.getRootClassPath() +"\\ehcache-shiro.xml"));
shirocache配置文件读取,好像说是用新版本的cache-core才会有这个问题,如果是系统自带的Ehcache版本不会有这个问题
plugins.add(newEhCachePlugin(PathKit.getRootClassPath()+" ehcache.xml"));
是因为找不到配置文件引起的,修改成指定文件名就没有问题了
plugins.add(newEhCachePlugin(PathKit.getRootClassPath()+" ehcache.xml"));
是因为找不到配置文件引起的,修改成指定文件名就没有问题了
这个是在Classes目录下,文件必须在这个目录下
如果在web-inf下,还是要修改目录参数
这个是在Classes目录下,文件必须在这个目录下
如果在web-inf下,还是要修改目录参数
me.add(newEhCachePlugin(PathKit.getRootClassPath() +"\\ehcache-shiro.xml"));
shirocache配置文件读取,好像说是用新版本的cache-core才会有这个问题,如果是系统自带的Ehcache版本不会有这个问题
JFinal自带的lib包里的Ehcache谢谢,我把maven配置的ehcache去掉就没报错了