Error creating bean with name 'redisTemplate’问题解决
org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘redisTemplate’ defined in class path resource [org/example/redistest/config/RedisConfig.class]: Failed to instantiate [org.springframework.data.redis.core.RedisTemplate]: Factory method ‘redisTemplate’ threw exception with message: com/fasterxml/jackson/databind/jsontype/TypeResolverBuilder
你的报错可能不和我的有些许不同。
这个报错一般是redisTemplate
Bean没有创建成功,具体问题看报错:
defined in class path resource [org/example/redistest/config/RedisConfig.class]:
RedisConfig是我的配置类,很显然配置类里有实例化的配置功能没有配置成功
解决方法:
详细检查配置的每一个方法,里面的内容是否都导入了正确的jar包(Maven)
// 设置redis value的序列化器
redisTemplate.setValueSerializer(new GenericJackson2JsonRedisSerializer());
// 设置hash key的序列化器
redisTemplate.setHashKeySerializer(new StringRedisSerializer());
// 设置hash value的序列化器
redisTemplate.setHashValueSerializer(new GenericJackson2JsonRedisSerializer());
我这里是`(new GenericJackson2JsonRedisSerializer());没配正确
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.15.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.15.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.15.0</version>
</dependency>
导包刷新就好了。