2014-06-10 136 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

感謝羅布,它的工作。 –