我最近将simple-spring-memcached从3.6.1版本升级到了4.1.1。但是,在此版本升级之后,每当我的代码尝试从缓存中获取值时,我都会收到WrappedCacheException。我在下面共享我的代码段:
@Transactional
@Cacheable(value = CACHE_NAME, key = "#id")
@Override
public TicketModel validate(final String id) {
TicketEntity ticketEntity = ticketEntityRepository.findOne(id);
if (ticketEntity == null) {
System.out.println("Ticket not found")
}
return something;
}
我的cacheManager bean看起来像:
@Bean
public CacheManager cacheManager() throws Exception {
List<SSMCache> cacheList = new ArrayList<>();
CacheFactory cacheFactory;
if (ELASTIC_CACHE_FACTORY.equals(cacheBean)) {
cacheFactory = elastiCacheFactory();
} else {
cacheFactory = memCacheFactory();
}
Cache cache = cacheFactory.getObject();
SSMCache aamCache = new SSMCache(cache, cacheTimeout, true);
cacheList.add(aamCache);
SSMCacheManager cacheManager = new SSMCacheManager();
cacheManager.setCaches(cacheList);
cacheManager.afterPropertiesSet();
return cacheManager;
}
我得到的确切异常如下:
SEVERE: Servlet.service() for servlet [jersey-servlet] in context with path [/user-service-web] threw exception [com.google.code.ssm.spring.WrappedCacheException] with root cause
com.google.code.ssm.spring.WrappedCacheException
at com.google.code.ssm.spring.SSMCache.logOrThrow(SSMCache.java:318)
at com.google.code.ssm.spring.SSMCache.getValue(SSMCache.java:285)
at com.google.code.ssm.spring.SSMCache.get(SSMCache.java:117)
at org.springframework.cache.interceptor.AbstractCacheInvoker.doGet(AbstractCacheInvoker.java:68)
at org.springframework.cache.interceptor.CacheAspectSupport.findInCaches(CacheAspectSupport.java:469)
at org.springframework.cache.interceptor.CacheAspectSupport.findCachedItem(CacheAspectSupport.java:435)
at org.springframework.cache.interceptor.CacheAspectSupport.execute(CacheAspectSupport.java:336)
at org.springframework.cache.interceptor.CacheAspectSupport.execute(CacheAspectSupport.java:302)
at org.springframework.cache.interceptor.CacheInterceptor.invoke(CacheInterceptor.java:61)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:655)
无论何时调用findOne(id)方法,我都会得到WrappedCacheException,并且代码将失败。请帮忙。
答案 0 :(得分:1)
在4.0.0之前,从底层缓存/客户端层引发的异常(例如IOException等)被SsmCache对象吞噬。在4.0.0之后,默认情况下,它们将被抛出给调用者。通过将SsmCache bean上的“ muteExceptions”标志设置为true,可以恢复到先前的行为。