springBoot连接远程Redis连接失败(已解决)

springBoot连接远程Redis连接失败(已解决) 问题:首先我是先用jedis进行的redis连接成功连接没有任何问题说明redis配置以及访问地址、端口、密码都是正确的。我的yml文件配置如下spring: redis: host: 远程ip地址 port: 6379 password: 密码但是当我使用springboot里面的redisTemplate进行连接的时候却发生了报错报错信息如下OpenJDK 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended org.springframework.data.redis.RedisConnectionFailureException: Unable to connect to Redis ..... Caused by: io.lettuce.core.RedisConnectionException: Unable to connect to localhost/unresolved:6379 ...... Caused by: io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection refused: no further information: localhost/127.0.0.1:6379 ..... Caused by: java.net.ConnectException: Connection refused: no further information .....然后我就很奇怪同样的访问为什么使用jedis能够成功但是使用redisTemplate就会失败解决过程:目光看向报错信息Caused by: io.lettuce.core.RedisConnectionException: Unable to connect to localhost/:6379这段表示在连接本地的redis的时候失败了我本地没有安装redis当然连接不上了但是为什么我配置的远程ip会连接到本地由于在springBoot中每个配置项都会有一个默认的自动配置类与之对应我这里配置了但是没效果显然配置失败项目使用默认的localhost进行连接的那为啥会配置失败呢在我查了半天教程之后总算在一篇教程里面发现了类似的情况如下升级springboot3.x踩坑记录-CSDN博客上面这篇文件就是作者在从spirngBoot2升到3之后redis连接失败了查看了源码之后发现redis的前缀发生了改变而我使用的是spirngBoot3上面的yml配置方法是springBoot2的配置方法所以产生了配置失效解决方法:根据源码可知springboot3中redis的前缀从“spring.redis”变成了spring.data.redis因此我们的配置文件需要再中间加一个dataspring: data: redis: host: 39.104.26.173 port: 6379 password: wen200389这样就能够成功连接了总结:一定要注意不同的springboot版本对应的配置文件的格式有可能会发生改变需要及时更正还有就是遇到问题多看源码许多问题真的能够通过看源码解决