EhCache,堆上层:未找到序列化程序

时间:2018-04-26 14:04:45

标签: java ehcache

我需要堆上缓存,所以我尝试使用ehcache v3.5.2

我有下一个测试:

public class TestEhCache {
  public static class MyObj {
    String message;

    public MyObj(String message) {
        this.message = message;
    }
  }

@Test
public void testDebugLogs() {
    CacheManager cacheManager;

    cacheManager = CacheManagerBuilder.newCacheManagerBuilder().build();
    cacheManager.init();

    Cache<String, MyObj> myCache = cacheManager.createCache("myCache",
            CacheConfigurationBuilder.newCacheConfigurationBuilder(String.class, MyObj.class, ResourcePoolsBuilder.heap(3))
            .build());
}

}

结果我看到了下一个警告

2018-04-26 19:56:26,237 [main] DEBUG org.ehcache.impl.internal.spi.serialization.DefaultSerializationProvider - Serializer for <java.lang.String> : org.ehcache.impl.serialization.StringSerializer@365185bd
2018-04-26 19:56:26,238 [main] DEBUG org.ehcache.core.EhcacheManager - Could not create serializers for myCache
org.ehcache.spi.serialization.UnsupportedTypeException: No serializer found for type 'it.TestEhcache$MyObj'
    at org.ehcache.impl.internal.spi.serialization.DefaultSerializationProvider.getSerializerClassFor(DefaultSerializationProvider.java:136)
    at org.ehcache.impl.internal.spi.serialization.DefaultSerializationProvider.createSerializer(DefaultSerializationProvider.java:98)
    at org.ehcache.impl.internal.spi.serialization.DefaultSerializationProvider.createValueSerializer(DefaultSerializationProvider.java:90)
    at org.ehcache.core.EhcacheManager.getStore(EhcacheManager.java:477)
    at org.ehcache.core.EhcacheManager.createNewEhcache(EhcacheManager.java:316)
    at org.ehcache.core.EhcacheManager.createCache(EhcacheManager.java:265)
    at org.ehcache.core.EhcacheManager.createCache(EhcacheManager.java:243)
    at it.TestEhcache.testDebugLogs(TestEhcache.java:29)
2018-04-26 19:56:26,243 [main] DEBUG org.ehcache.impl.internal.spi.copy.DefaultCopyProvider - Copier for <java.lang.String> : org.ehcache.impl.copy.IdentityCopier@150c158
2018-04-26 19:56:26,244 [main] DEBUG org.ehcache.impl.internal.spi.copy.DefaultCopyProvider - Copier for <it.TestEhcache$MyObj> : org.ehcache.impl.copy.IdentityCopier@4524411f
2018-04-26 19:56:26,292 [main] DEBUG class org.ehcache.core.Ehcache-myCache - Initialize successful.
2018-04-26 19:56:26,292 [main] INFO  org.ehcache.core.EhcacheManager - Cache 'myCache' created in EhcacheManager.

如何抑制&#34;没有为类型&#34找到序列化器;警告?据我所知,无堆层不需要它。 (见路易斯的Jacomet回复here

1 个答案:

答案 0 :(得分:1)

降低日志级别 - 这是在DEBUG打印的,因此从技术上讲它不是警告。

确实你的堆上缓存可以正常工作。