Spring boot 集成Redis的步骤如下:

1.在pom.xml中配置相关的jar依赖;

<!--加载spring boot redis包 -->

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
2.在Springboot核心配置文件application.properties中配置redis连接信息:
spring.redis.host=127.0.0.1
spring.redis.port=6379
spring.redis.password=123456
3.配置了上面的步骤,Spring boot将自定配置RedisTemplate,在需要操作redis的类中注入redisTemplate;
在使用的类中注入:
@Autowried
private RedisTemplate<String,String> redisTemplate;
@Atuowried
private RedisTemplate<Object,Object> redisTemplate;
spring boot帮我们注入的RedisTemplate类,泛型里面只能写<String,String>,<Object,Object>

相关文章:

  • 2022-03-10
  • 2022-02-04
猜你喜欢
  • 2021-12-27
  • 2021-07-06
  • 2022-12-23
  • 2021-04-18
  • 2021-10-10
  • 2021-08-27
  • 2021-12-01
相关资源
相似解决方案