【Spring Boot】java.lang.NoSuchMethodError: org.springframework.web.util.UrlPathHelper.getLookupPathForRequest(Ljavax/servlet/http/HttpServletRequest;Ljava/lang/String;)Ljava/lang/String;

Digest:今天Spring Boot 应用启动成功,访问接口出现如下错误,不知到导致问题关键所在,记录一下这个问题。

浏览器报500错误

【Spring Boot】java.lang.NoSuchMethodError: org.springframework.web.util.UrlPathHelper.getLookupPathForRequest(Ljavax/servlet/http/HttpServletRequest;Ljava/lang/String;)Ljava/lang/String;_第1张图片

项目代码如下

Controller.java

package com.lints.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author Lints
 * @Date 2019/10/31 9:06
 * @Description This is description of class
 * @Since version-1.0
 */
@RestController
public class HelloController {
    /**
     * @Author Lints
     * @Date 2019/10/31 9:06
     * @Description 这用于处理浏览器hello请求
     * @Param null
     * @Return java.lang.String
     * @Since version-1.0
     */
    @ResponseBody
    @RequestMapping("/hello")
    public String helloWorld(){
        return "Hello World!";
    }
}
View Code

 HelloWorldApp.java

package com.lints;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
 * @Author Lints
 * @Date  20:47
 * @Description This is a Spring Boot application
 * @Since version-1.0
 */

@SpringBootApplication
public class HelloWorldApp {
   /**
    * @Author Lints
    * @Date 2019/10/30 21:25
    * @Description This is description of method
    * @Param [args]
    * @Return void
    * @Since version-1.0
    */
    public static void main(String[] args) {
        //启动Spring应用
        SpringApplication.run(HelloWorldApp.class,args);
    }
}
View Code

pom.xml

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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0modelVersion>

  <parent>
    <groupId>org.springframework.bootgroupId>
    <artifactId>spring-boot-starter-parentartifactId>
    <version>2.2.0.RELEASEversion>
    <relativePath/>
  parent>

  <groupId>com.lintsgroupId>
  <artifactId>spring-boot-helloworldartifactId>
  <version>1.0-SNAPSHOTversion>

  <name>spring-boot-helloworldname>
  
  <url>http://www.example.comurl>

  <properties>
    <project.build.sourceEncoding>UTF-8project.build.sourceEncoding>
    <maven.compiler.source>1.7maven.compiler.source>
    <maven.compiler.target>1.7maven.compiler.target>
  properties>

  <dependencies>
    <dependency>
      <groupId>junitgroupId>
      <artifactId>junitartifactId>
      <version>4.11version>
      <scope>testscope>
    dependency>
    <dependency>
      <groupId>org.springframework.bootgroupId>
      <artifactId>spring-boot-starter-webartifactId>
    dependency>
      <dependency>
          <groupId>org.springframeworkgroupId>
          <artifactId>spring-coreartifactId>
          <version>5.2.0.RELEASEversion>
      dependency>
    <dependency>
      <groupId>org.springframeworkgroupId>
      <artifactId>spring-webartifactId>
      <version>5.1.8.RELEASEversion>
    dependency>
  dependencies>

  <build>
    <pluginManagement>
      <plugins>
        
        <plugin>
          <artifactId>maven-clean-pluginartifactId>
          <version>3.1.0version>
        plugin>
        
        <plugin>
          <artifactId>maven-resources-pluginartifactId>
          <version>3.0.2version>
        plugin>
        <plugin>
          <artifactId>maven-compiler-pluginartifactId>
          <version>3.8.0version>
        plugin>
        <plugin>
          <artifactId>maven-surefire-pluginartifactId>
          <version>2.22.1version>
        plugin>
        <plugin>
          <artifactId>maven-jar-pluginartifactId>
          <version>3.0.2version>
        plugin>
        <plugin>
          <artifactId>maven-install-pluginartifactId>
          <version>2.5.2version>
        plugin>
        <plugin>
          <artifactId>maven-deploy-pluginartifactId>
          <version>2.8.2version>
        plugin>
        
        <plugin>
          <artifactId>maven-site-pluginartifactId>
          <version>3.7.1version>
        plugin>
        <plugin>
          <artifactId>maven-project-info-reports-pluginartifactId>
          <version>3.0.0version>
        plugin>
      plugins>
    pluginManagement>
  build>
project>
View Code

解决办法

将pom.xml中 Spring版本换成 2.1.6 问题解决

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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0modelVersion>

  <parent>
    <groupId>org.springframework.bootgroupId>
    <artifactId>spring-boot-starter-parentartifactId>

    

    <version>2.1.6.RELEASEversion>
    <relativePath/>
  parent>
View Code

你可能感兴趣的:(【Spring Boot】java.lang.NoSuchMethodError: org.springframework.web.util.UrlPathHelper.getLookupPathForRequest(Ljavax/servlet/http/HttpServletRequest;Ljava/lang/String;)Ljava/lang/String;)