2015-09-02 1 views
0

Je ne peux pas utiliser simple-spring-memcached avec le type de sérialisation par défaut défini sur JSON. L'erreur que je reçois est:Sérialisation JSON avec simple memcached à ressort

java.lang.IllegalArgumentException: Cannot use JSON serialization because dedicated cache transcoder is null! 
at com.google.code.ssm.CacheImpl.set(CacheImpl.java:290) ~[simple-spring-memcached-3.5.0.jar:na] 
at com.google.code.ssm.CacheImpl.set(CacheImpl.java:125) ~[simple-spring-memcached-3.5.0.jar:na] 
at com.google.code.ssm.PrefixedCacheImpl.set(PrefixedCacheImpl.java:130) ~[simple-spring-memcached-3.5.0.jar:na] 
at com.google.code.ssm.spring.SSMCache.put(SSMCache.java:159) ~[spring-cache-3.5.0.jar:na] 
at org.springframework.cache.interceptor.CacheAspectSupport.update(CacheAspectSupport.java:351) [spring-context-3.2.9.RELEASE.jar:3.2.9.RELEASE] 
at org.springframework.cache.interceptor.CacheAspectSupport.execute(CacheAspectSupport.java:214) [spring-context-3.2.9.RELEASE.jar:3.2.9.RELEASE] 
at org.springframework.cache.interceptor.CacheInterceptor.invoke(CacheInterceptor.java:66) [spring-context-3.2.9.RELEASE.jar:3.2.9.RELEASE] 
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) [spring-aop-3.2.9.RELEASE.jar:3.2.9.RELEASE] 
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204) [spring-aop-3.2.9.RELEASE.jar:3.2.9.RELEASE] 
at com.sun.proxy.$Proxy105.findByValue(Unknown Source) [na:na] 

Ma configuration est:

@Configuration() 
    @EnableAspectJAutoProxy 
    @EnableCaching 
    public class SimpleSpringCacheConfig { 

    @Autowired 
    private Environment env; 

    private static final String DEFAULT_MEMCACHED_HOST = "127.0.0.1:11211"; 
    private static final Integer DEFAULT_MEMCACHED_TTL_SECONDS = 3600; 
    private static final Integer DEFAULT_MEMCACHED_TIMEOUT_MILLIS = 500; 

    private static final String PROPERTY_MEMCACHED_HOSTS = "service.caching.memcached.hosts"; 
    private static final String PROPERTY_DEFAULT_TTL_SECONDS="service.caching.default.ttl.seconds"; 

    private static final Logger log = LoggerFactory.getLogger(SimpleSpringCacheConfig.class); 

    //reference config on https://code.google.com/p/simple-spring-memcached/wiki/Getting_Started#Spring_3.1_Cache_Integration 
    @Bean 
    public CacheManager cacheManager() throws Exception 
    { 
      MemcacheClientFactoryImpl cacheClientFactory = new MemcacheClientFactoryImpl(); 
      AddressProvider addressProvider = new DefaultAddressProvider(env.getProperty(PROPERTY_MEMCACHED_HOSTS, DEFAULT_MEMCACHED_HOST)); 
      CacheConfiguration cacheConfiguration = new CacheConfiguration(); 

      cacheConfiguration.setKeyPrefixSeparator("_"); 
      cacheConfiguration.setUseNameAsKeyPrefix(true); 
      cacheConfiguration.setConsistentHashing(true); 
      cacheConfiguration.setOperationTimeout(DEFAULT_MEMCACHED_TIMEOUT_MILLIS); 

      CacheFactory cacheFactory = new CacheFactory(); 
      cacheFactory.setCacheName("simpleMemcachedCache"); 
      cacheFactory.setCacheClientFactory(cacheClientFactory); 
      cacheFactory.setAddressProvider(addressProvider); 
      cacheFactory.setConfiguration(cacheConfiguration); 
      cacheFactory.setDefaultSerializationType(SerializationType.JSON); 

      Cache object = cacheFactory.getObject(); 

      int ttl = env.getProperty(PROPERTY_DEFAULT_TTL_SECONDS, Integer.class, DEFAULT_MEMCACHED_TTL_SECONDS); 

      //@CacheEvict(..., "allEntries" = true) won't work because allowClear is false, 
      //so we won't flush accidentally all entries from memcached instance.. 
      SSMCache ssmCache = new SSMCache(object, ttl, false); 

      ArrayList<SSMCache> ssmCaches = new ArrayList<SSMCache>(); 
      ssmCaches.add(0, ssmCache); 

      SSMCacheManager ssmCacheManager = new SSMCacheManager(); 
      ssmCacheManager.setCaches(ssmCaches); 

      return ssmCacheManager; 
    } 
} 

Selon le guide ici https://code.google.com/p/simple-spring-memcached/wiki/Getting_Started#Serialization il ne semble pas nécessaire de définir un transcodeur personnalisé. Que pourrais-je faire de mal?

J'utilise les versions suivantes .. printemps-cache: V3.5.0 fournisseur spymemcached: V3.5.0 printemps: v3.2.8.RELEASE

Répondre

1

Il n'y a pas d'obligation de définir JSON transcodeur si vous utilisez la configuration XML de SSM. Dans votre cas, vous devez initialiser entièrement objet CacheFactory invoquez donc:

cacheFactory.afterPropertiesSet(); 

juste avant

Cache object = cacheFactory.getObject(); 
+0

merci! ça a marché.. – Gagan