Shiladittya Chakraborty
Shiladittya Chakraborty

Reputation: 4418

EHCache import not working after upgrading spring boot

EHCache configuration not working after upgrading spring boot 3.0.2

Below is the gradle dependency

plugins {
    id 'java'
    id 'org.springframework.boot' version '3.0.2'
    id 'io.spring.dependency-management' version '1.0.15.RELEASE'
}

group = 'com.image'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '17'


repositories {
    mavenCentral()
}

dependencies {  
    implementation 'org.springframework.boot:spring-boot-starter-cache'
    implementation 'net.sf.ehcache:ehcache:2.9.1'
    
}

EHCache configuration Class

package com.image.cache.config;

import java.lang.reflect.Field;

import org.springframework.cache.ehcache.EhCacheCacheManager;
import org.springframework.cache.ehcache.EhCacheManagerFactoryBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;    
import net.sf.ehcache.Cache;
import net.sf.ehcache.config.CacheConfiguration;

@Configuration
public class EhCacheConfig {

    @Bean
    EhCacheManagerFactoryBean cacheManager() {
        return new EhCacheManagerFactoryBean();
    }

    @Bean
    EhCacheCacheManager testEhCacheManager() throws IllegalArgumentException, IllegalAccessException {
        return new EhCacheCacheManager(cacheManager().getObject());
    }

    private CacheConfiguration setCacheConfiguration(String cacheName) {
        CacheConfiguration cacheConfig = new CacheConfiguration()
                .eternal(false) // if true, timeouts are ignored
                .timeToIdleSeconds(3600) // time since last accessed before item is marked for removal
                .timeToLiveSeconds(3600 * 24) // time since inserted before item is marked for removal
                .maxEntriesLocalHeap(10000) // total items that can be stored in cache
                .memoryStoreEvictionPolicy("LRU") // eviction policy for when items exceed cache. LRU = Least Recently Used
                .name(cacheName);
        return cacheConfig;
    }

}

After upgrading to spring boot 3 getting below exception

The import org.springframework.cache.ehcache cannot be resolved

Upvotes: 1

Views: 2100

Answers (0)

Related Questions