我在从缓存中获取价值时面临问题。
java.lang.RuntimeException: java.lang.ClassCastException: com.mycom.admin.domain.User cannot be cast to com.mycom.admin.domain.User
缓存配置
@Configuration @EnableCaching @AutoConfigureAfter(value = { MetricsConfiguration.class, DatabaseConfiguration.class }) @Profile("!" + Constants.SPRING_PROFILE_FAST) public class MemcachedCacheConfiguration extends CachingConfigurerSupport { private final Logger log = LoggerFactory.getLogger(MemcachedCacheConfiguration.class); @Override @Bean public CacheManager cacheManager() { ExtendedSSMCacheManager cacheManager = new ExtendedSSMCacheManager(); try { List<SSMCache> list = new ArrayList<>(); list.add(new SSMCache(defaultCache("apiCache"), 86400, false)); cacheManager.setCaches(list); } catch (Exception e) { e.printStackTrace(); } return cacheManager; } @Override public CacheResolver cacheResolver() { return null; } @Override public CacheErrorHandler errorHandler() { return null; } private Cache defaultCache(String cacheName) throws Exception { CacheFactory cacheFactory = new CacheFactory(); cacheFactory.setCacheName(cacheName); cacheFactory.setCacheClientFactory(new MemcacheClientFactoryImpl()); String serverHost = "127.0.0.1:11211"; cacheFactory.setAddressProvider(new DefaultAddressProvider(serverHost)); cacheFactory.setConfiguration(cacheConfiguration()); return cacheFactory.getObject(); } @Bean public CacheConfiguration cacheConfiguration() { CacheConfiguration cacheConfiguration = new CacheConfiguration(); cacheConfiguration.setConsistentHashing(true); return cacheConfiguration; } }
并带有注释
@Cacheable(value = "apiCache#86400", key = "'User-'.concat(#login)")
我正在使用com.google.code.simple-spring-memcached 3.5.0
值正在缓存,但在获取应用程序时会抛出类强制转换错误。可能是什么问题。
全栈跟踪
这是Devtools的已知限制。反序列化高速缓存条目时,该对象未附加到正确的类加载器。
您可以通过多种方式解决此问题:
simple
spring.cache.type
application-dev.properties