问题1-spring-boot版本和org.springframework的spring-web兼容的版本

115 篇文章 0 订阅
1 篇文章 0 订阅

报错问题如下:

Description:

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

  org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.createHandlerMethod(AbstractHandlerMethodMapping.java:345)

The following method did not exist:

    org.springframework.web.method.HandlerMethod.<init>(Ljava/lang/String;Lorg/springframework/beans/factory/BeanFactory;Lorg/springframework/context/MessageSource;Ljava/lang/reflect/Method;)V

The calling method's class, org.springframework.web.servlet.handler.AbstractHandlerMethodMapping, was loaded from the following location:

    jar:file:/F:/JAVA/MavenInstall/maven-Repository/org/springframework/spring-webmvc/5.3.23/spring-webmvc-5.3.23.jar!/org/springframework/web/servlet/handler/AbstractHandlerMethodMapping.class

The called method's class, org.springframework.web.method.HandlerMethod, is available from the following locations:

    jar:file:/F:/JAVA/MavenInstall/maven-Repository/org/springframework/spring-web/5.3.1/spring-web-5.3.1.jar!/org/springframework/web/method/HandlerMethod.class

The called method's class hierarchy was loaded from the following locations:

    org.springframework.web.method.HandlerMethod: file:/F:/JAVA/MavenInstall/maven-Repository/org/springframework/spring-web/5.3.1/spring-web-5.3.1.jar
 

===

具体报错原因

Correct the classpath of your applicat ion so that it contains compatible versions of the classes org.springframework.web.servlet.handler.AbstractHandlerMethodMapping and org.springframework.web.method.HandlerMethod 

============

解决方法直接看!!!

【2、查询spring-boot版本和org.springframework的spring-web兼容的版本】

==========

1、解决过程

查询AI解决方法:

输入的问题:

Correct the classpath of your applicat ion so that it contains compatible versions of the classes org.springframework.web.servlet.handler.AbstractHandlerMethodMapping and org.springframework.web.method.HandlerMethod 报错的原因和解决方法

解释如下:

这个错误通常是由于在同一个项目中,引入了不同版本的 Spring Framework 库,导致其中某些类或方法不兼容而引起的。在你的情况下,是 org.springframework.web.servlet.handler.AbstractHandlerMethodMappingorg.springframework.web.method.HandlerMethod 这两个类的版本不兼容。

解决方法如下:

  1. 检查依赖项的版本: 检查你项目构建配置文件中的依赖项(例如 Maven 的 pom.xml 或 Gradle 的 build.gradle 文件),确保所有的 Spring Framework 依赖项都与兼容的版本对齐。确保 org.springframework.web.servletorg.springframework.web 模块的版本匹配,并且没有冲突。

  2. 排除冲突的传递依赖项: 如果你使用的是像 Maven 这样的构建工具,你可以排除那些可能会引入不兼容的 Spring Framework 类库版本的传递依赖项。识别任何导致版本冲突的依赖项,并将其排除在你的项目之外。

  3. 更新 Spring Framework 版本: 考虑更新你的 Spring Framework 依赖项到一个支持所需构造函数的版本。这可能涉及更新构建配置文件中的版本号,并解决与其他库的潜在兼容性问题。

  4. 清理和重新构建: 在更改依赖项后,执行清理和重新构建你的项目,以确保所有依赖项都已正确解析,并且类路径包含所需类的兼容版本。

  5. 运行和测试: 调整类路径以包含 Spring Framework 的必要类的兼容版本后,运行你的应用程序并进行测试,以验证问题是否已解决。确保所有功能按预期工作,没有涉及缺失构造函数的方法调用错误。

按照以上步骤并确保你的应用程序的类路径包含 Spring Framework 所需的兼容类的版本,应该可以解决你遇到的“方法不存在”错误

====

尝试解决方法:

1、尝试用 AI提出的 【2、更新 Spring Framework 版本】

以前pom文件里面spring-boot版本和org.springframework的spring-web的版本

  当时idea自动引入的版本

 <spring-boot.version>2.6.4</spring-boot.version>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>5.3.1</version>
        </dependency>

2、查询spring-boot版本和org.springframework的spring-web兼容的版本

springboot和springframework版本依赖关系

3、成功方法:

更新springframework的spring-web版本

  <spring-boot.version>2.6.13</spring-boot.version>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>5.3.16</version>
        </dependency>

成功画面:

更新springframework版本后整个pom文件内容

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.yupi</groupId>
    <artifactId>user-center</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>user-center</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>1.8</java.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <spring-boot.version>2.6.13</spring-boot.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
            <version>2.6.4</version>
        </dependency>
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>2.2.2</version>
        </dependency>
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
            <version>3.5.1</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.12.0</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.13.2</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>5.3.16</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>${spring-boot.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>${spring-boot.version}</version>
                <configuration>
                    <mainClass>com.yupi.usercenter.UserCenterApplication</mainClass>
                    <skip>true</skip>
                </configuration>
                <executions>
                    <execution>
                        <id>repackage</id>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>

  • 45
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值