An attempt was made to call the method xxx but it does not exist

场景

在公司项目中做配置迁移的时候,服务启动时报错

报错信息

Description:

An attempt was made to call the method redis.clients.jedis.Jedis.<init>(Ljava/lang/String;IIIZLjavax/net/ssl/SSLSocketFactory;Ljavax/net/ssl/SSLParameters;Ljavax/net/ssl/HostnameVerifier;)V but it does not exist. Its class, redis.clients.jedis.Jedis, is available from the following locations:

    jar:file:/home/work/one-front-callin/app/BOOT-INF/lib/jedis-2.8.0.jar!/redis/clients/jedis/Jedis.class

It was loaded from the following location:

    jar:file:/home/work/one-front-callin/app/BOOT-INF/lib/jedis-2.8.0.jar!/


Action:

Correct the classpath of your application so that it contains a single, compatible version of redis.clients.jedis.Jedis

这种问题一看就是maven引入第三方依赖版本冲突或不匹配相关的问题,该问题导致这个springboot服务启动报错,其实这种报错还是看上去比较舒服的,这个报错提示是非常到位,咱们试着理解下这个报错提示

分三步部分解读报错

1、您的应用程序尝试调用 redis.clients.jedis.Jedis 类的构造函数,该构造函数的参数类型依次为java.lang.String、javax.net.ssl.SSLSocketFactory,javax.net.ssl.SSLParameters, javax.net.ssl.HostnameVerifier(是构造函数的意思,是构造函数的字节码写法),但该构造函数不存在

An attempt was made to call the method 

redis.clients.jedis.Jedis.<init>(Ljava/lang/String;IIIZLjavax/net/ssl/SSLSocketFactory;Ljavax/net/ssl/SSLParameters;Ljavax/net/ssl/HostnameVerifier;)V 

but it does not exist

该构造函数不存在?是jar包冲突了吗?带着这些问题继续读第二部分的报错信息

2、该构造器所在的类redis.clients.jedis.Jedis,存在于/home/work/one-front-callin/app/BOOT-INF/lib/jedis-2.8.0.jar!/redis/clients/jedis/Jedis.class,被加载的位置是/home/work/one-front-callin/app/BOOT-INF/lib/jedis-2.8.0.jar!/,也就是说我们所部署的项目中有且只有一个jedis相关的jar包的,经排查发现项目中确实只有一个2.8.0的jedis jar包,所以可以断定这并非是项目中存在多个jedis jar包导致冲突的

 Its class, redis.clients.jedis.Jedis, is available from the following locations:

    jar:file:/home/work/one-front-callin/app/BOOT-INF/lib/jedis-2.8.0.jar!/redis/clients/jedis/Jedis.class

It was loaded from the following location:

    jar:file:/home/work/one-front-callin/app/BOOT-INF/lib/jedis-2.8.0.jar!/

3、这是报错中给的解决该问题的建议,建议我们纠正应用程序即jedis的类路径,使其包含redis.clients.jedi .jedis的单一兼容版本

Action:

Correct the classpath of your application so that it contains a single, compatible version of redis.clients.jedis.Jedis

个人理解就是项目中调用redis.clients.jedis.Jedis的版本和我们当前这个2.8版本不一样,所以调用redis.clients.jedis.Jedis的构造器时无法从2.8版本中的redis.clients.jedis.Jedis中匹配到要调用的这个构造器

redis.clients.jedis.Jedis.<init>(Ljava/lang/String;IIIZLjavax/net/ssl/SSLSocketFactory;Ljavax/net/ssl/SSLParameters;Ljavax/net/ssl/HostnameVerifier;)V 

至于是在哪个地方调用的redis.clients.jedis.Jedis的构造器我们不用太纠结,应该是某个第三方jar包中的类调用的,我们只需要找到合适的jedis jar包版本即可了

所以我查阅了下新版的jedis版本,碰巧发现jeids 2.9版本中存在这个构造器
An attempt was made to call the method xxx but it does not exist_第1张图片

所果断把2.8版本升级到2.9版本
在这里插入图片描述

问题解决

你可能感兴趣的:(error,spring,boot,后端,java)