shiro ehcache配置

来源:互联网 发布:软件开发找对象 编辑:程序博客网 时间:2024/06/05 19:03

        shiro 使用 ehcache只需要在配置中加一些东西就好,首先,添加ehcache的jar ,然后在src下,添加一个ehcache的配置:内容如下:

<ehcache updateCheck="false" name="Cache">  
    <defaultCache  
            maxElementsInMemory="10000"  
            eternal="false"  
            timeToIdleSeconds="120"  
            timeToLiveSeconds="120"  
            overflowToDisk="false"  
            diskPersistent="false"  
            diskExpiryThreadIntervalSeconds="120"  
            />  
</ehcache>

需要在applicationContext中加入:

    <bean id="ehcacheManager" class="org.apache.shiro.cache.ehcache.EhCacheManager">  
          <!--classpath是缓存属性的配置文件  -->  
          <property name="cacheManagerConfigFile" value="classpath:config/ehcache-shiro.xml" />  
    </bean>

把ehcacheManager注入到:

<bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
<!--设置自定义realm -->
<property name="realm" ref="monitorRealm" />
   <property name="cacheManager" ref="shiroEhcacheManager"></property>
</bean>

0 0