2012-01-06 54 views
7

如何在使用Apache shiro时设置cacheManager属性。在调试时,我得到的信息如下:CacheManager属性已设置 - Apache Shiro

80104 [[email protected]] INFO org.apache.shiro.realm.AuthorizingRealm - No cache or cacheManager properties have been set. Authorization cache cannot be obtained. 

我正在使用JSF2和Google Cloud SQL。

回答

4

如果使用Shiro的INI配置,则像设置其他bean属性一样设置SecurityManager的cacheManager属性。例如:

[main] 

cacheManager = com.something.impl.SomeCacheManager 
# config cacheManager as necessary, e.g. 
# cacheManager.foo = bar 

securityManager.cacheManager = $cacheManager 

可以使用出的现成的EhCacheManager或自己实现CacheManagerCache接口来使用自定义缓存后备存储器(例如内存缓存,一致性,GigaSpaces的,任何现代的NoSQL键/价值商店等)

1

EhCacheManager似乎不是shiro-core 1.2.1的一部分(无论如何都在Maven包中)。我加入的问题解决了以下信息才能shiro.ini我的[主]部分:

[main] 
builtInCacheManager = org.apache.shiro.cache.MemoryConstrainedCacheManager 
securityManager.cacheManager = $builtInCacheManager 
+3

嗨阿兰 - 我们不能强迫所有用户四郎依赖的Ehcache,这样的Ehcache支持是作为一个[插件] (http://search.maven.org/#search%7Cga%7C1%7Cshiro-ehcache)。只需将它添加到运行时类路径中,即可立即使用EhCacheManager。 HTH! – 2012-08-10 18:07:31

+1

啊,不知道。不过,当你提到它是包含在核心库中的开箱即用的时候。谢谢! – 2012-08-10 18:50:38