shiro缓存配置
realm的缓存
方法一:
在securityManager配置中添加cacheManager配置项,会注入到realm中。
方法二:在realm中配置。
realm本身实现了CacheManagerAware接口
public interface CacheManagerAware { /** * Sets the available CacheManager instance on this component. * * @param cacheManager the CacheManager instance to set on this component. */ void setCacheManager(CacheManager cacheManager); }
securityManager不只会帮realm注入cacheManager,还会帮sessionManager注入cacheManager
<bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
<property name="cacheManager" ref="redisCacheManager" />
<property name="realm" ref="myRealm" />
<property name="sessionManager" ref="sessionManager"/>
</bean>
这样的话,realm和sessionManager就不用再配缓存