The spring-boot integration redis startup project reports an error with the following message:
defining a bean of type 'org.springframework.data.redis.core.RedisTemplate' in your configuration.
orConsider defining a bean of type 'org.springframework.data.redis.core.StringRedisTemplate' in your configuration.
Modify the pom file
Change the
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
</dependency>
is changed to
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
After modification, if you want to customize redistemplate, you can refer to the following configuration
@Bean
public RedisTemplate<String, Object> template(RedisConnectionFactory factory) {
// Create RedisTemplate<String, Object>object
RedisTemplate<String, Object> template = new RedisTemplate<>();
// Configuring the connection factory
template.setConnectionFactory(factory);
// Define the Jackson2JsonRedisSerializer serialization object
Jackson2JsonRedisSerializer<Object> jacksonSeial = new Jackson2JsonRedisSerializer<>(Object.class);
ObjectMapper om = new ObjectMapper();
// Specify the field, field, get and set to be serialized, and the range of modifiers, ANY of which are included in private and public
om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
// Specify the type of serialized input, the class must be non-final modified, final modified class, such as String, Integer, etc. will report an exception
om.activateDefaultTyping(LaissezFaireSubTypeValidator.instance, ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.WRAPPER_ARRAY);
jacksonSeial.setObjectMapper(om);
StringRedisSerializer stringSerial = new StringRedisSerializer();
// redis key Serialization method used stringSerial
template.setKeySerializer(stringSerial);
// redis value Serialization method usedjackson
template.setValueSerializer(jacksonSeial);
// redis hash key Serialization method usedstringSerial
template.setHashKeySerializer(stringSerial);
// redis hash value Serialization method usedjackson
template.setHashValueSerializer(jacksonSeial);
template.afterPropertiesSet();
return template;
}
Read More:
- [Solved] Consider defining a bean of type ‘org.springframework.data.redis.core.RedisTemplate‘ in your configu
- [Solved] java.lang.IllegalAccessError: class org.springframework.data.redis.core.$ Proxy237 cannot access its superinterface org.springframework.data.redis.core.RedisConnectionUtils$RedisConnectionProxy
- [Solved] Redis Error: org.springframework.data.redis.RedisConnectionFailureExceptionjava.net.SocketTimeoutException
- [Solved] Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type…
- [Solved] RedisTemplate increment Error: io.lettuce.core.RedisCommandExecutionException: ERR value is not an intege
- [Solved] org.springframework.context.ApplicationContextException: Failed to start bean ‘org.springframework.a
- [Solved] org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘org
- JPA multiple-data source startup error: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘t
- [Solved] org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘xxx‘
- [Siolved] org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘webMvcObject
- [Solved] Error creating bean with name ‘org.springframework.web.servlet.handler.SimpleUrlHandlerMapping#0‘:
- [Solved] org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name
- [Solved] Classnotfoundexception: org.springframework.core.nativedetector error
- org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘testApplicat
- [Integrate the mobile MAS SMS service] SDK start error: NoSuchMethodError: org.springframework.core.annotation.AnnotatedElementUtil
- [Solved] org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class
- Eureka Build Error: org.springframework.beans.factory.BeanCreationException: Error creating bean with name
- [Solved] Springboot uses redis to add LocaldateTime Java 8 error
- Fastjson Error: Error: Cannot create inner bean ‘org.springframework.http.converter.json.MappingJackson2HttpMessageConverter
- [Solved] Spring Aop Error: Error creating bean with name ‘org.springframework.aop.config.internalAutoProxyCreator‘