2014-06-10 19 views
0

我使用的是Spring Security ACL,它需要定义缓存。到目前为止,我使用的是:春季安全的JCache ACL缓存

@Bean(name = { "defaultAclCache", "aclCache" }) 
protected AclCache defaultAclCache() { 
    return new SpringCacheBasedAclCache(defaultAclJCacheFactory(), defaultPermissionGrantingStrategy(), defaultAclAuthorizationStrategy()); 
} 

它一切正常。不过,我切换到使用jcache现在defaultAclJCacheFactory()返回javax.cache.Cache一个实例,它是与SpringCacheBasedAclCache不兼容:

@Bean(name = { "defaultAclJCacheFactory", "aclJCacheFactory" }) 
protected Cache defaultAclJCacheFactory() { 
    return cacheManager.getCache("acl_cache"); 
} 

我试图寻找一个JCache实施org.springframework.security.acls.model.AclCache但只有这一个春天缓存和一个用于的Ehcache。有没有计划推出jcache

回答

1

你应该能够使用JCacheCacheManager实施方案以获得的org.springframework.cache.Cache实例例如:

@Bean(name = { "defaultAclCache", "aclCache" }) 
protected AclCache defaultAclCache(org.springframework.cache.CacheManager springCacheManager) { 
    org.springframework.cache.Cache cache = 
     springCacheManager.getCache("acl_cache"); 
    return new SpringCacheBasedAclCache(cache, 
     defaultPermissionGrantingStrategy(), 
     defaultAclAuthorizationStrategy()); 
} 

// Depending on your configuration, you may not even need this 
@Bean 
public JCacheCacheManager springCacheManager(javax.cache.CacheManager cacheManager) { 
    return new JCacheCacheManager(cacheManager); 
} 
+0

感谢罗布,它的工作。 –