springboot中使用缓存shiro-ehcache
生活随笔
收集整理的這篇文章主要介紹了
springboot中使用缓存shiro-ehcache
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
在pom.xml中注入緩存依賴,版本(Sep 09, 2016)
spring-context-support
包含支持UI模版(Velocity,FreeMarker,JasperReports),
郵件服務,
腳本服務(JRuby),
緩存Cache(EHCache),
任務計劃Scheduling(uartz)。
在ShiroConfiguration中注入緩存
/*** shiro緩存管理器;* 需要注入對應的其它的實體類中:* 1、安全管理器:securityManager* 可見securityManager是整個shiro的核心;* @return*/@Beanpublic EhCacheManager ehCacheManager(){System.out.println("ShiroConfiguration.getEhCacheManager()");EhCacheManager cacheManager = new EhCacheManager();cacheManager.setCacheManagerConfigFile("classpath:config/ehcache-shiro.xml");return cacheManager;}將緩存對象注入到SecurityManager中:
@Beanpublic SecurityManager securityManager(){DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager();securityManager.setRealm(myShiroRealm());securityManager.setCacheManager(ehCacheManager());return securityManager;}添加緩存配置文件:
在src/main/resouces/config添加ehcache-shiro.xml配置文件:
在配置文件上已經有很詳細的解釋了,所以這里就過多介紹ehcache的配置了。
運行程序訪問:http://127.0.0.1:8080/userInfo/userAdd
查看控制臺的打印信息:
權限配置-->MyShiroRealm.doGetAuthorizationInfo()
這個信息就只打印一次了,說明我們的緩存生效了。
文章主要參考于作者林祥纖的博客
http://412887952-qq-com.iteye.com/blog/2299780
總結
以上是生活随笔為你收集整理的springboot中使用缓存shiro-ehcache的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: linux常用网络命令ping和arpi
- 下一篇: iOS:个人浅谈工厂模式