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

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

18 回复

添加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();
    }

nutzboot shiroCacheManager 可以集成 caffeine 缓存吗

配置 缓存 shiro.session.cache.type=ehcache
加入shiro ehcache依赖包 启动 还是用|shiro.session.cache.type |no | |memory |设置使用的缓存类型

        <dependency>
            <groupId>org.apache.shiro</groupId>
            <artifactId>shiro-ehcache</artifactId>
            <version>1.4.0</version>
        </dependency>

启动 输出 这个 是配置不对吗

[DEBUG] 11:49:08.665 net.sf.ehcache.config.ConfigurationHelper.createCacheManagerEventListener(ConfigurationHelper.java:189) - No CacheManagerEventListenerFactory class specified. Skipping...
[DEBUG] 11:49:13.711 net.sf.ehcache.Cache.createBootstrapCacheLoader(Cache.java:1044) - No BootstrapCacheLoaderFactory class specified. Skipping...
[DEBUG] 11:49:13.711 net.sf.ehcache.Cache.createCacheWriter(Cache.java:1017) - CacheWriter factory not configured. Skipping...

看nutzcn的配置

不对,nutzcn好像是用shiro.ini配的

加上ehcache应该就可以了,是报错还是怎样了?

shiro-ehcache引用很老的ehcache,需要排除掉

CacheManagerEventListenerFactory并不会用到

添加回复
请先登陆
回到顶部