zoukankan      html  css  js  c++  java
  • shiro学习记录(三)

    1.使用ehcache缓存权限数据

    ehcache是专门缓存插件,可以缓存Java对象,提高系统性能。

    l ehcache提供的jar包:

    第一步:在pom.xml文件中引入ehcache的依赖

    <!-- 引入ehcache的依赖 -->
            <dependency>
                <groupId>net.sf.ehcache</groupId>
                <artifactId>ehcache-core</artifactId>
                <version>2.6.6</version>
            </dependency>

    第二步:在项目中提供ehcache的配置文件

    <ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../config/ehcache.xsd">
        <diskStore path="java.io.tmpdir"/><!-- 当前操作系统的临时目录 -->
        <defaultCache
                maxElementsInMemory="10000"
                eternal="false"
                timeToIdleSeconds="120"
                timeToLiveSeconds="120"
                overflowToDisk="true"
                maxElementsOnDisk="10000000"
                diskPersistent="false"
                diskExpiryThreadIntervalSeconds="120"
                memoryStoreEvictionPolicy="LRU"
                />
    </ehcache>

    第三步:在spring配置文件中配置缓存管理器对象,并注入给安全管理器对象

    <!-- 注册安全管理器对象 -->
        <bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
            <property name="realm" ref="bosRealm"/>
            <!-- 注入缓存管理器 -->
            <property name="cacheManager" ref="cacheManager"/>
        </bean>
        
        <!-- 注册缓存管理器 -->
        <bean id="cacheManager" class="org.apache.shiro.cache.ehcache.EhCacheManager">
            <!-- 注入ehcache的配置文件 -->
            <property name="cacheManagerConfigFile" value="classpath:ehcache.xml"/>
        </bean>
  • 相关阅读:
    A. Vasya and Book
    B. Curiosity Has No Limits
    A. Link/Cut Tree
    C. Yuhao and a Parenthesis
    D2. Magic Powder
    B. Approximating a Constant Range
    51nod1185 威佐夫游戏 V2 (模拟乘法)
    博弈论(巴什博奕,威佐夫博弈,尼姆博弈,斐波那契博弈)
    sg函数模板
    D.Starry的神奇魔法(矩阵快速幂)
  • 原文地址:https://www.cnblogs.com/FanJava/p/9360351.html
Copyright © 2011-2022 走看看