缓存使用ehcache,
修改权限的时候一直提示cacheManager找不到。
然后就发现使用DefaultRealm(自定义Realm)的时候如下代码所示:
// 清空权限缓存
DefaultRealm realm=new DefaultRealm();
SimplePrincipalCollection principals = new SimplePrincipalCollection();
Account account = accountService.getAccountById(accountId);
principals.add(account.getUsername(), realm.getName());
realm.clearCachedAuthorizationInfo(principals);
问题就出在第一句
DefaultRealm realm=new DefaultRealm();
因为没有使用spring的注入,所有才导致cacheManager一直为null,切忌切忌。
改成自动注入,ok完美解决问题。