2016-03-04 85 views
0

嗨,我想知道是否有可能在Scala中利用Spring註釋緩存。我已經嘗試過,但正在接收下面的錯誤。我從一個依賴於scala包的java包運行應用程序。可能在Scala中使用Spring緩存

No cache could be resolved for 'CacheableOperation[public scala.collection.immutable.List MerchantDataGateway.getAllMerchants()] 

我的配置類

@Configuration 
@EnableCaching 
@ComponentScan(basePackages = "xxx.xxx.xxx.xxx") 
public class EnvironmentHelperConfig { 

    @Bean 
    public CacheManager getCacheManager() { 
     final int ttl = 12; 
     final int maxCacheSize = 1012; 

     GuavaCacheManager result = new GuavaCacheManager(); 
     result.setCacheBuilder(CacheBuilder 
       .newBuilder() 
       .expireAfterWrite(ttl, TimeUnit.HOURS) 
       .maximumSize(maxCacheSize)); 

     return result; 
    } 
} 

我的斯卡拉類

@Component 
class MerchantDataGateway { 

    @Autowired 
    var fmcsProxy: MerchantResource = null; 

    @Cacheable 
    def getAllMerchants(): List[MerchantViewModel] = { 
    val merchants = getAllMerchantsFromFMCS() 
    merchants.map(merchant => MerchantViewModel.getLightWeightInstance(merchant)) 
    } 
} 

回答

2

添加一個名字@Cacheable註釋:

@Cacheable(Array("MerchantDataGateway.getAllMerchants")) 
0

它需要一個名字,或者輸入值爲

@Cacheable(value = Array("MerchantDataGateway.getAllMerchants")