spring-boot-devtools causing ClassCastException while getting from cache.

I am facing issue while getting value from cache.

java.lang.RuntimeException: java.lang.ClassCastException: com.mycom.admin.domain.User cannot be cast to com.mycom.admin.domain.User

Cache Configuration

@AutoConfigureAfter(value = { MetricsConfiguration.class, DatabaseConfiguration.class })
@Profile("!" + Constants.SPRING_PROFILE_FAST)
public class MemcachedCacheConfiguration extends CachingConfigurerSupport {

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

    public CacheManager cacheManager() {
        ExtendedSSMCacheManager cacheManager = new ExtendedSSMCacheManager();
        try {
            List<SSMCache> list = new ArrayList<>();
            list.add(new SSMCache(defaultCache("apiCache"), 86400, false));
        } catch (Exception e) {
        return cacheManager;

    public CacheResolver cacheResolver() {
        return null;

    public CacheErrorHandler errorHandler() {
        return null;

    private Cache defaultCache(String cacheName) throws Exception {
        CacheFactory cacheFactory = new CacheFactory();
        cacheFactory.setCacheClientFactory(new MemcacheClientFactoryImpl());
        String serverHost = "";
        cacheFactory.setAddressProvider(new DefaultAddressProvider(serverHost));
        return cacheFactory.getObject();

    public CacheConfiguration cacheConfiguration() {
        CacheConfiguration cacheConfiguration = new CacheConfiguration();
        return cacheConfiguration;


And annotated with

@Cacheable(value = "apiCache#86400", key = "'User-'.concat(#login)")

I am using 3.5.0

Value is getting cached but while getting application throws class cast error. What would be the possible issues.

Full stack trace


  • This is a known limitation of Devtools. When the cache entry is deserialized, the object is not attached to the proper classloader.

    There are various ways you can fix this issue:

    1. Disable cache when you're running your application in development
    2. Use a different cache manager (if you're using Spring Boot 1.3, you could force a simple cache manager using the spring.cache.type property in and enable the dev profile in your IDE)
    3. Configure memcached (and things that are cached) to run in the application classloader. I wouldn't recommend that option since the two first above are much easier to implement