springBoot redis -- spring-boot-starter-data-redis与spring-boot-starter-redis两个包的区别

本文详细介绍了不同版本的Spring Boot中引入Redis的方式变化。从1.4.0开始,spring-boot-starter-data-redis取代了spring-boot-starter-redis,并在1.5.0及更高版本成为唯一选项。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、下面是Spring Boot的版本为1.5.9的时候的spring-boot-starter-data-redis的jar包的情况:

2、下面是Spring Boot的版本为1.4.0的时候的spring-boot-starter-data-redis的jar包的情况:

3、下面是Spring Boot的版本为1.4.0的时候的spring-boot-starter-redis的jar包的情况:

可以看出两个包并没有区别,只是版本的区别。。

但是当springBoot的版本为1.4.7 以上的时候,spring-boot-starter-redis 就空了。要想引入redis就只能选择有data的

下面对SpringBoot 的版本为1.4.7的时候的情况进行考察一下:

经认证,在spring boot的版本号为1.5.0的时候 添加spring-boot-starter-reids就找不到jar包了,也就是这个jar包直接被废弃了。所以千万要注意的是:如果你的spring boot的版本号在1.5.0以后的,添加redis的jar包就必须是spring-boot-starter-data-redis。。。。

在这里还要说的一点就是:

在spring boot的版本号为1.4.0 之后,才有 spring-boot-starter-data-redis的jar包。。也就是把 spring-boot-starter-redis的jar包修改成  spring-boot-starter-data-redis jar包。。。

总结下来就是:

如果你的spring boot的版本号是1.4.0  到1.5.0 之间,添加redis的jar包的时候  添加 成 spring-boot-starter-data-redis  和  spring-boot-starter-redis  是都可以的。。。

但是   如果你的spring boot的版本号  是1.4.0 以前 也就是1.3.8 版本以前,添加redis 的 jar包 就必须是 spring-boot-starter-redis 的jar包。。

对于Spring Cloud中Spring BootRedis集成的情况,特别是涉及到队列设置时,你提到的是`spring-boot-starter-data-redis`用于连接Redis 2.x,但你提到项目使用的Spring Boot版本较低(1.8),并且由于兼容性限制无法直接使用用户名密码进行身份验证。 如果你想要在Spring Boot应用中使用Spring Data Redis来管理Redis队列,并添加用户名密码支持,你可能需要采取以下步骤: 1. **自定义配置**[^1]: - 定制Spring Boot的自动配置类以覆盖默认行为。这通常涉及重写或扩展内置的`RedisConnectionFactory`创建器,添加对用户名/密码的支持。例如,你可以尝试修改`JedisConnectionFactory`的构造函数来接受并传递这些凭据。 ```java @Configuration public class CustomRedisConfig { @Bean public JedisConnectionFactory jedisConnectionFactory(RedisProperties properties) { JedisConnectionFactory factory = new JedisConnectionFactory(); factory.setHostName(properties.getHost()); factory.setPort(Integer.parseInt(properties.getPort().toString())); if (StringUtils.hasText(properties.getPassword())) { factory.setPassword(properties.getPassword()); } // ...其他配置 return factory; } } ``` 2. **启用密码保护**: - 如果Redis服务器确实需要密码保护,确保在Redis服务器上已经启用了密码认证,并将密码配置到Spring Boot的`application.properties`或`application.yml`文件中。 ```properties spring.redis.password=test@123 ``` 3. **注意版本兼容性**: - 考虑将Spring BootSpring Data Redis升级到更高版本,以便更好地支持Redis 2.x更现代的功能,尽管这可能会导致其他依赖项也需要更新。 4. **测试队列操作**: - 使用自定义配置后的RedisTemplate或Jedis实例来操作Redis队列,如`ListOperations`或`Lpush`、`Rpop`等命令。 记得在实际部署之前进行全面的测试,以确保新的配置能够正常工作。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值