tit*_*geo 8 java memcached spring-boot spring-cache jhipster
我从缓存中获取价值时遇到问题.
java.lang.RuntimeException: java.lang.ClassCastException: com.mycom.admin.domain.User cannot be cast to com.mycom.admin.domain.User
Run Code Online (Sandbox Code Playgroud)
缓存配置
@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;
}
}
Run Code Online (Sandbox Code Playgroud)
并附有注释
@Cacheable(value = "apiCache#86400", key = "'User-'.concat(#login)")
Run Code Online (Sandbox Code Playgroud)
我正在使用com.google.code.simple-spring-memcached 3.5.0
值正在缓存但是在获取应用程序时会抛出类转换错误.什么是可能的问题.
这是Devtools的已知限制.反序列化高速缓存条目时,该对象未附加到正确的类加载器.
您可以通过多种方式解决此问题:
simple
使用该spring.cache.type
属性强制缓存管理器application-dev.properties
并在IDE中启用dev配置文件) 归档时间: |
|
查看次数: |
3686 次 |
最近记录: |