1. 程式人生 > >springboot+springcache+shiro+Redis整合時@Cacheable、@Transactional等註解失效的問題

springboot+springcache+shiro+Redis整合時@Cacheable、@Transactional等註解失效的問題

edi nbsp bubuko oot 自定義 bsp mage boot color

問題描述:

1.springboot整合shiro之前@Cacheable、@Transactional等註解都可以正常使用;

2.整合了shiro之後,自定義MyShiroRealm中註入RoleUserService時 RolerUservice中的@Cacheable、@Transaction都失效了。

MyShiroRealm代碼:

技術分享圖片

RoleUserService代碼:

技術分享圖片

原因:shiro和cache在引用service實例順序問題,shiro引入應在cache後,

shiro配置文件中引用realm屬性bean中引用的service采用延遲加載策略。

解決方法:在MyShiroRealm註入RoleUserService時@Lazy註解(采用延遲加載策略)

MyShiroRealm改進後代碼:

技術分享圖片



springboot+springcache+shiro+Redis整合時@Cacheable、@Transactional等註解失效的問題