springboot配置redis项目启动时错误怎么解决

编辑: admin 分类: mysql 发布时间: 2023-06-10 来源:互联网

springboot配置redis项目启动时的错误

在刚开始学redis时,我照着网上的教程,把redis和jedis整合到spring boot,整合完毕后,启动项目总是失败

总是爆出下面的错误

Correct the classpath of your application so that it contains a single, compatible version of org.springframework.data.repository.config.RepositoryConfigurationSource

***************************
APPLICATION FAILED TO START
***************************

Description:

An attempt was made to call the method org.springframework.data.repository.config.RepositoryConfigurationSource.getAttribute(Ljava/lang/String;)Ljava/lang/String; but it does not exist. Its class, org.springframework.data.repository.config.RepositoryConfigurationSource, is available from the following locations:

jar:file:/D:/m2/repository/org/springframework/data/spring-data-commons/2.0.10.RELEASE/spring-data-commons-2.0.10.RELEASE.jar!/org/springframework/data/repository/config/RepositoryConfigurationSource.class

It was loaded from the following location:

file:/D:/m2/repository/org/springframework/data/spring-data-commons/2.0.10.RELEASE/spring-data-commons-2.0.10.RELEASE.jar

Action:

Correct the classpath of your application so that it contains a single, compatible version of org.springframework.data.repository.config.RepositoryConfigurationSource

2018-11-22 13:03:51.398 INFO 2196 --- [ main] ConfigServletWebServerApplicationContext : Closing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@1a451d4d: startup date [Thu Nov 22 13:03:50 CST 2018]; root of context hierarchy

Process finished with exit code 1

然后我在网上找了很久,都没有关于这个错误的解决办法,偶然看到一篇博客,它在启动项目时也出现了类型错误,也是jar包冲突,然后那个博主是通过改redis和jedis的版本号解决的,我也把版本号都改成和那个博主相同的,但启动后还是出现相同的错误。

后来就想如果我把版本号都去掉,让“spring-boot-starter-parent”自动为我们提供对应版本的jar包,这样就可以避免自己指定版本号时,可能会有一些意想不到的冲突。因此,当我移除了redis和jedis的版本号时,项目成功地启动了

What a strange error..

springboot配置redis项目启动时错误怎么解决

解决springboot项目启动时redis报错

出现ERR Client sent AUTH, but no password is set的问题

首先看下我springboot配置redis的部分如图:

springboot配置redis项目启动时错误怎么解决

显然上面配置了redis的启动密码为123456,

本地redis版本为3.0.1 在redis.windows.conf文件中requirepass内容也修改了密码为123456,这里说下,在去除requirepass前面的#号时一定注意还有一个空格要去除,不然会报错:

Invalid argument during startup: unknown conf file parameter : requirepass

这时,说明redis密码与springboot的一致,接下来就是启动redis再启动springboot。

启动Redis的方法是进入其安装目录,运行redis-server.exe,然后按照正常流程启动。然而一旦启动了springboot,访问redis就会出错,如下图所示:

springboot配置redis项目启动时错误怎么解决

一开始以为是我Pom.xml文件中引入的为2.9.0的redis依赖导致的版本不兼容,一直去找Redis的2.9.0的安装包竟然网上没有。浪费了半天时间。

后来才发现,这个报错是告诉我没有设置密码。原因就是启动时的方法错误。

请务必记住,启动本地redis,如果设置了密码记得带上配置文件,启动命令完整为:

redis-server.exe redis.windows.conf
登录后复制【本文由:高防cdn http://www.558idc.com/gfcdn.html 复制请保留原URL】