我需要堆上缓存,因此我正在尝试使用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.


如何抑制“未找到类型的序列化程序”警告?据我了解,无堆层不是必需的。 (请参阅路易斯的Jacomet答复here

最佳答案

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

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

10-08 20:18