Springboot集成Redis步骤

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>

猜你喜欢

转载自www.cnblogs.com/ysq0908/p/10692973.html