【问题标题】:Java - Shiro - ehcache configJava - Shiro - ehcache 配置
【发布时间】:2015-04-01 02:28:05
【问题描述】:

我在使用Spring (v4.1.4) 的Java Web 项目中使用Shiro(v1.2.3)。

我为 shiro 启用了Ehcache,以帮助存储 shiro 会话。


我的问题是:

我是否需要在 ehcache.xml 配置文件中为 shiro 会话定义一个 <cache> 实体,或者 shiro 会自动管理它?

一句话,我是否需要将以下配置段放入ehcache-shiro.xml

<cache name="shiro-activeSessionCache" maxElementsInMemory="10000" overflowToDisk="true" eternal="true"
    timeToLiveSeconds="0" timeToIdleSeconds="0" diskPersistent="true" diskExpiryThreadIntervalSeconds="600" />

【问题讨论】:

    标签: java spring ehcache shiro


    【解决方案1】:

    不,如果默认设置适合您,则不需要。 ehcache.xml 文件是 shiro-ehcache 模块的一部分,默认使用。您引用的设置与此文件中定义的设置相同。正如Shiro doc about session management 提到的:

    默认情况下,EhCacheManager 使用 Shiro 特定的 ehcache.xml 文件 设置会话缓存区域和必要的设置 确保正确存储和检索会话。

    但是,如果您希望更改缓存设置,或配置您的 拥有 ehcache.xml 或 EHCache net.sf.ehcache.CacheManager 实例,你 将需要配置缓存区域以确保会话是 正确处理。

    如果您查看默认的 ehcache.xml 文件,您将看到 以下 shiro-activeSessionCache 缓存配置:

    <cache name="shiro-activeSessionCache"
            maxElementsInMemory="10000"
            overflowToDisk="true"
            eternal="true"
            timeToLiveSeconds="0"
            timeToIdleSeconds="0"
            diskPersistent="true"
            diskExpiryThreadIntervalSeconds="600"/> 
    

    如果您希望使用自己的 ehcache.xml 文件,请确保您已经定义了类似的缓存 满足 Shiro 需求的条目

    【讨论】:

    • 我在默认配置文件中看到了一个名为org.apache.shiro.realm.text.PropertiesRealm-0-accounts 的缓存,你能帮忙解释一下这是做什么的吗,谢谢。
    • 嘿,看看邮件列表中的这个解释,但一般来说你不应该担心,因为这是 lib 内部实现的一部分:mail-archives.apache.org/mod_mbox/shiro-user/201208.mbox/…
    猜你喜欢
    • 2013-11-19
    • 1970-01-01
    • 1970-01-01
    • 2018-07-31
    • 1970-01-01
    • 2015-03-04
    • 1970-01-01
    • 2014-01-04
    • 2019-06-29
    相关资源
    最近更新 更多