Quantcast
Channel: Active questions tagged redis+java - Stack Overflow
Viewing all articles
Browse latest Browse all 2222

Cannot find cache named 'xxxx' for Builder - ElasticCache AWS and Spring Boot

$
0
0

I am trying to connect my Spring Boot project to ElasticCache Redis in AWS. However, I get this error:

java.lang.IllegalArgumentException: Cannot find cache named 'XXX' for Builder[public <Class Name> <method Name>(java.lang.String)] caches=['xxxx'] | key='#key' | keyGenerator='' | cacheManager='' | cacheResolver='' | condition='' | unless='' | sync='false'

application.properties

spring.cache.type=redisspring.redis.host=*****.*****.****.****.cache.amazonaws.comspring.redis.port=6379spring.redis.prefix=testingspring.cache.cache-names=XXXXXspring.redis.cluster.nodes=node_1, node_2, node_3

RedisConfig.java

@Configuration@EnableCachingpublic class RedisConfig {    @Value("${spring.redis.host}")    private String redisHostName;    @Value("${spring.redis.port}")    private int redisPort;    @Value("${spring.redis.prefix}")    private String redisPrefix;    @Bean    JedisConnectionFactory jedisConnectionFactory() {        System.out.println(redisHostName);        System.out.println(redisPort);        RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration(redisHostName, redisPort);        return new JedisConnectionFactory(redisStandaloneConfiguration);    }    @Bean(value = "redisTemplate")    public RedisTemplate<String, Object> redisTemplate() {        RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();        redisTemplate.setConnectionFactory(jedisConnectionFactory());        return redisTemplate;    }    @Primary    @Bean(name = "cacheManager") // Default cache manager is infinite    public CacheManager cacheManager(RedisConnectionFactory redisConnectionFactory) {        return RedisCacheManager.builder(redisConnectionFactory).cacheDefaults(RedisCacheConfiguration.defaultCacheConfig().prefixKeysWith(redisPrefix)).build();    }}

UserDetailsServiceImpl.java

@Override    @Cacheable(value = "userdetails", key="{#userId}")    public User getUserDetails(String userId) {        User user =userDAO.getUserbyID(userId);        return user;    }

build.gradle

implementation group: 'org.springframework.boot', name: 'spring-boot-starter-cache', version: '2.6.7'implementation group: 'org.springframework.boot', name: 'spring-boot-starter-data-redis', version: '2.6.7'implementation group: 'redis.clients', name: 'jedis', version: '3.7.1'implementation group: 'org.springframework.cloud', name: 'spring-cloud-aws-dependencies', version: '2.2.6.RELEASE', ext: 'pom'

On invoking the API I get the below error:

java.lang.IllegalArgumentException: Cannot find cache named 'XXX' for Builder[public <Class Name> <method Name>(java.lang.String)] caches=['xxxx'] | key='#key' | keyGenerator='' | cacheManager='' | cacheResolver='' | condition='' | unless='' | sync='false'

Any idea where I am going wrong?


Viewing all articles
Browse latest Browse all 2222

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>