NutzCN Logo
问答 nutz boot shiro如何使用ehcache
发布于 129天前 作者 yy321973351 182 次浏览 复制 上一个帖子 下一个帖子
标签:

nutz boot shiro如何使用ehcache进行缓存配置

11 回复

添加ehcache依赖,并设置 shiro.session.cache.type=ehcache 就可以了

var ioc = {
        "cacheManager" : {
            "type" : "net.sf.ehcache.CacheManager",
            "factory" : "net.sf.ehcache.CacheManager#getCacheManager",
            "args" : ["nutzbook"] // 对应shiro.ini中指定的ehcache.xml中定义的name
        }
        /*
        // 如果不需要shiro初始化的Ehcache, 使用下面的方式配置
        "cacheManager" : {
            "type" : "net.sf.ehcache.CacheManager",
            "factory" : "net.sf.ehcache.CacheManager#create"
        }
         */
};


如果不用js 该如何配置

不需要这个, 加ehcache依赖和shiro.session.cache.type=ehcache就行

我想把缓存的输出出来如: CacheManager cacheManager = ioc.get(CacheManager.class);
log.debug("Ehcache CacheManager = " + cacheManager);

org.nutz.ioc.IocException: IocBean[mainLauncher -> cacheManager] For object [cacheManager] - type:[interface org.apache.shiro.cache.CacheManager]
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:250)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:271)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:161)
	at io.nutz.demo.MainLauncher.init(MainLauncher.java:56)
	at io.nutz.demo.MainLauncher$FM$init$cff301be46c87e2fbea60f4ef344bacb.invoke(MainLauncher.java)
	at org.nutz.ioc.impl.ObjectMakerImpl$2.trigger(ObjectMakerImpl.java:180)
	at org.nutz.ioc.weaver.DefaultWeaver.onCreate(DefaultWeaver.java:89)
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:141)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:241)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:271)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:161)
	at org.nutz.boot.NbApp.execute(NbApp.java:208)
	at org.nutz.boot.NbApp.run(NbApp.java:177)
	at io.nutz.demo.MainLauncher.main(MainLauncher.java:65)
Caused by: org.nutz.ioc.ObjectLoadException: Object 'cacheManager' without define!
	at org.nutz.ioc.loader.combo.ComboIocLoader.load(ComboIocLoader.java:157)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:195)
	... 13 more

哦? 是单独用cacheManager? 这样写就是

@IocBean
public class MyBeans {
     @IocBean
     public CacheManager cacheManager() {
        CacheManager cacheManager = CacheManager.getInstance();
        if (cacheManager != null)
            return cacheManager;
        return net.sf.ehcache.CacheManager.newInstance();
     }
}
cacheExecutor : {
            type : "org.nutz.plugins.cache.dao.DaoCacheInterceptor",
            fields : {
                cacheProvider : {refer:"cacheProvider"},
                // 需要缓存的表名
                cachedTableNames : ["t_user_profile",
                                    //"t_user", "t_role", "t_permission", "t_role_permission"
                                    ]
            }
        },
        // 基于Ehcache的DaoCacheProvider
        cacheProvider : {
            type : "org.nutz.plugins.cache.dao.impl.provider.EhcacheDaoCacheProvider",
            fields : {
                cacheManager : {refer:"cacheManager"} // 引用ehcache.js中定义的CacheManager
            },
            events : {
                create : "init"
            }
        }

这俩个呢

看配置手册嘛, 不需要加js 的

```
nutz.dao.interceptor.cache.provider.type=ehcache
nutz.dao.interceptor.cache.table.names=XXX,XXX,XXX
````

就是没找到nutz boot 的手册在哪里啊

main方法没写对吧, 有setPrintProcDoc就打印手册了

    public static void main(String[] args) throws Exception {
        new NbApp().setArgs(args).setPrintProcDoc(true).run();
    }
添加回复
请先登陆
回到顶部