my issue is the same of this Spring Ehcache3 cause exception with with key-type and value-type, the only difference is that I don't have an .xml file, I have this CacheConfig instead:
@Configuration
@EnableCaching
public class CacheConfig {
@Bean
public CacheManager cacheManager() {
// creation of cache configuration
CacheConfiguration<String, String> cacheConfiguration = CacheConfigurationBuilder
.newCacheConfigurationBuilder(
String.class, String.class,
ResourcePoolsBuilder.heap(1000).build()
).build();
// fetching cacheManager
CachingProvider cachingProvider = Caching.getCachingProvider();
CacheManager cacheManager = cachingProvider.getCacheManager();
// parsing ehcache configuration to something SpringBoot will understand
javax.cache.configuration.Configuration<String, String> configuration = Eh107Configuration.fromEhcacheCacheConfiguration(cacheConfiguration);
// creating as many caches as you want
cacheManager.createCache("serviceHostName", configuration);
// add shutdown hook to close cacheManager
Runtime.getRuntime().addShutdownHook(new Thread(cacheManager::close));
// return Bean
return cacheManager;
}
}
But when I deploy project, I have this exception:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cacheManager' defined in class path resource [org/springframework/boot/autoconfigure/cache/JCacheCacheConfiguration.class]: Cache [serviceHostName] specifies key/value types. Use getCache(String, Class, Class)....
Caused by: java.lang.IllegalArgumentException: Cache [serviceHostName] specifies key/value types. Use getCache(String, Class, Class)
at org.ehcache.jsr107.Eh107CacheManager.getCache(Eh107CacheManager.java:271) ~[ehcache-3.0.0.jar:3.0.0 6973aca181d2b3e0010945a89933f3c99f4460c5]....
What is need to do, that I can use own key type and value types?