配置shiro.ini

打开conf目录下的shiro.ini,在[main]节点的末尾,加入

  1. cacheManager = org.apache.shiro.cache.ehcache.EhCacheManager
  2. cacheManager.cacheManagerConfigFile=classpath:ehcache.xml
  3. nutzdao_realm.cacheManager = $cacheManager

留意一下配置文件的路径,指向的就是上一小节定义的ehcache,并且让nutzdao_realm引用这个缓存管理器.

如果需要缓存shiro的Session,可以加入这些配置(不推荐)

  1. sessionDAO = org.apache.shiro.session.mgt.eis.EnterpriseCacheSessionDAO
  2. sessionManager.sessionDAO = $sessionDAO
  3. securityManager.sessionManager = $sessionManager
  4. securityManager.cacheManager = $cacheManager