验证码跟ehcash整合

1.所有配置文件如下:

`

    <bean class="com.mocent.shiro.captcha.DreamCaptcha">
    <property name="cacheManager" ref="shiroSpringCacheManager"/>
        <!-- 复用半小时缓存 -->
        <property name="cacheName" value="halfHour"/>
    </bean>

`
`

    <bean id="shiroSpringCacheManager" class="com.mocent.shiro.cash.ShiroSpringCacheManager">
        <property name="cacheManager" ref="cacheManager"/>
</bean>

`
`
3.

    <property name="cacheManager" ref="ehcacheManager"/>
    <property name="transactionAware" value="true"/>
</bean>

`
`

<bean id="ehcacheManager" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
    <property name="configLocation" value="classpath:cash/ehcache.xml"/>
</bean>`

`5.

    <cache name="halfHour" 
    maxElementsInMemory="10000"
    maxElementsOnDisk="100000" 
    eternal="false" 
    timeToIdleSeconds="1800"
    timeToLiveSeconds="1800"
    overflowToDisk="false"
    diskPersistent="false" />

`

2. 类图

image

image
这个bean将要被IOC实例化,通过get set的方式传参数进去,被赋值的属性是cacheManager和cacheName。cacheName是直接赋值为halfHour字符串,而cacheManager属性来自
image
ShiroSpringCacheManager的属性以及方法如下
image
也是使用get set的方式设置值被设值的属性是cacheManager,cacheManager来自
image
image
经过一系列的传递后发现最终的验证码的缓存管理类是EhCacheCacheManager,它实现了org.springframework.cache.CacheManager接口可以被com.mocent.shiro.captcha.DreamCaptcha使用
继续往下看
image
org.springframework.cache.CacheManager的cacheManager参数是来自org.springframework.cache.ehcache.EhCacheManagerFactoryBean他是EhCacheCacheManager的工厂类,生成EhCacheCacheManager的配置文件是
cash/ehcache.xml里面有一个名为halfHour的缓存配置
image
这也是验证码生成类com.mocent.shiro.captcha.DreamCaptcha的另外一个属性的来源

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值