【发布时间】:2021-04-22 10:05:51
【问题描述】:
我想为 Spring Cache 执行下面的操作。
-
检查传递的字符串是否存在于缓存中。如果存在则返回true,如果不存在则添加到缓存; checkInCache(String str)
-
从缓存中驱逐字符串 逐出(字符串 str)
尝试如下
@组件 公共类 FlightCache {
public static final Logger log = LoggerFactory.getLogger(FlightCache.class);
@Autowired
CacheManager cacheManager;
public boolean isFlightKeyPresent(final String flightKey) {
final ValueWrapper existingValue = cacheManager.getCache("flightCache").get(flightKey);
log.info("existingValueexistingValue " + existingValue);
if (existingValue == null) {
cacheManager.getCache("flightCache").put(flightKey, flightKey);
return false;
} else {
return true;
}
}
并在配置类上添加@EnableCaching注解。
错误:
required a bean of type 'org.springframework.cache.CacheManager' that could not be found. The injection point has the following annotations: - @org.springframework.beans.factory.annotation.Autowired(required=true)Action:Consider defining a bean of type 'org.springframework.cache.CacheManager' in your configuration.
【问题讨论】:
-
请通过这个tutorial
标签: spring spring-cache