解决 An attempt was made to call a method that does not exist. 问题详解

这篇具有很好参考价值的文章主要介绍了解决 An attempt was made to call a method that does not exist. 问题详解。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

哈喽大家好,我是阿Q。今天在开发代码的过程中,由于手抖,不知道引入了什么包依赖,导致项目启动一直报错,特写本文来记录下解决问题的经过。

有想赚点外块|技术交流的朋友,欢迎来撩

问题描述

报错信息如下

Description:

An attempt was made to call a method that does not exist. The attempt was made from the following location:

    io.undertow.websockets.jsr.Bootstrap.handleDeployment(Bootstrap.java:84)

The following method did not exist:

    javax.servlet.ServletContext.getClassLoader()Ljava/lang/ClassLoader;

The method's class, javax.servlet.ServletContext, is available from the following locations:

    jar:file:/E:/.m2/repository/javax/servlet/servlet-api/2.5/servlet-api-2.5.jar!/javax/servlet/ServletContext.class
    jar:file:/E:/.m2/repository/jakarta/servlet/jakarta.servlet-api/4.0.4/jakarta.servlet-api-4.0.4.jar!/javax/servlet/ServletContext.class

The class hierarchy was loaded from the following locations:

    javax.servlet.ServletContext: file:/E:/.m2/repository/javax/servlet/servlet-api/2.5/servlet-api-2.5.jar


Action:

Correct the classpath of your application so that it contains a single, compatible version of javax.servlet.ServletContext

报错描述

试图从以下位置去调用一个不存在的方法:io.undertow.websockets.jsr.Bootstrap.handleDeployment(Bootstrap.java:84);

javax.servlet.ServletContext.getClassLoader()Ljava/lang/ClassLoader;该方法不存在;

该方法的类javax.servlet.ServletContext可从以下位置获得:

 jar:file:/E:/.m2/repository/javax/servlet/servlet-api/2.5/servlet-api-2.5.jar!/javax/servlet/ServletContext.class
 jar:file:/E:/.m2/repository/jakarta/servlet/jakarta.servlet-api/4.0.4/jakarta.servlet-api-4.0.4.jar!/javax/servlet/ServletContext.class

类层次结构是从以下位置加载的:javax.servlet.ServletContext: file:/E:/.m2/repository/javax/servlet/servlet-api/2.5/servlet-api-2.5.jar

更正应用程序的类路径,使其包含一个单独的兼容版本的javax.servlet.ServletContext

上边的解释说人话就是servlet-apijakarta.servlet-api下的 ServletContext.class 冲突了,需要修改一下版本依赖。

解决方法

首先打开IDEA的 setting 设置

解决 An attempt was made to call a method that does not exist. 问题详解
然后选择 Plugins 插件,下载Maven Helper插件,如果安装之后不生效,可以重启一下 IDEA
解决 An attempt was made to call a method that does not exist. 问题详解
最后打开 pom.xml 文件,选择 Dependency Analyzer 切换页,选择 All Dependencies as Tree 选项,然后搜索 javax,然后右键选择 Exclude 排除重复依赖就可以了。
解决 An attempt was made to call a method that does not exist. 问题详解
点完之后会发现 pom.xml 文件中会出现如下代码

<dependency>
  <groupId>com.xxx.kas.swagger</groupId>
  <artifactId>swagger-spring-mvc-core</artifactId>
  <version>1.0-SNAPSHOT</version>
  <exclusions>
	<exclusion>
	  <artifactId>servlet-api</artifactId>
	  <groupId>javax.servlet</groupId>
	</exclusion>
  </exclusions>
</dependency>

如果排除之后依然报错,可以选择上图的Jump To Source跳转到对应的仓库内将对应版本删除即可。

刷新下依赖,发现正常启动了,搞定。

总结

以后再遇到这种包依赖冲突的问题都可以使用Maven Helper这个插件来轻松解决,妈妈再也不用担心我的学习了😃。文章来源地址https://www.toymoban.com/news/detail-486963.html

到了这里,关于解决 An attempt was made to call a method that does not exist. 问题详解的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包