Error while creating Bean even though the Dependency Bean is there

Viewed 12325

I have my Configuration Class with some Dependent Beans

public class WebConfig{
    @Bean
        @Qualifier("geojedis")
        public StringRedisTemplate geoJedisTemplate(
                @Qualifier("geographyJedisConnectionFactory") final JedisConnectionFactory connectionFactory) {

            // Create a RedisTemplate implementation which is basically of string
            // data structure.
            StringRedisTemplate redisTemplate = new StringRedisTemplate(connectionFactory);

            return redisTemplate;
        }

    @Bean
        @Qualifier("capacityStringRedisTemplate")
        public StringRedisTemplate capacityStringRedisTemplate(
                @Qualifier("capacityJedisConnectionFactory") final JedisConnectionFactory connectionFactory) {

            // Create a RedisTemplate implementation which is basically of string
            // data structure.
            StringRedisTemplate redisTemplate = new StringRedisTemplate(connectionFactory);

            return redisTemplate;
        }

    @Bean
        public JedisConnectionFactory geographyJedisConnectionFactory() {
            JedisConnectionFactory connectionFactory = new JedisConnectionFactory();
            return connectionFactory;
        }

    @Bean
        public JedisConnectionFactory capacityJedisConnectionFactory() {
            JedisConnectionFactory connectionFactory = new JedisConnectionFactory();
            return connectionFactory;
        }
    }

But I am getting the below error. When i checked the configurations all are fine and I have also defined the Qualifier for mapping the correct dependencies. Any help is much appreciated.

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'redisTemplate' defined in class path resource [org/springframework/boot/autoconfigure/redis/RedisAutoConfiguration$RedisConfiguration.class]: Unsatisfied dependency expressed through constructor argument with index 0 of type [org.springframework.data.redis.connection.RedisConnectionFactory]: : No qualifying bean of type [org.springframework.data.redis.connection.RedisConnectionFactory] is defined: expected single matching bean but found 2: geographyJedisConnectionFactory,capacityJedisConnectionFactory; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [org.springframework.data.redis.connection.RedisConnectionFactory] is defined: expected single matching bean but found 2: geographyJedisConnectionFactory,capacityJedisConnectionFactory

3 Answers

use @EnableAutoConfiguration(exclude = RedisAutoConfiguration.class) above your config class and provide the custom connection properties

Related