【问题标题】:java.lang.NoClassDefFoundError: org/springframework/web/util/UriTemplateHandlerjava.lang.NoClassDefFoundError: org/springframework/web/util/UriTemplateHandler
【发布时间】:2020-04-16 08:49:59
【问题描述】:

我是 Springboot 新手,想运行一个示例项目。

在 Intellij 中执行时出现以下错误: java.lang.NoClassDefFoundError: org/springframework/web/util/UriTemplateHandler

POM 是: https://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 org.springframework.boot spring-boot-starter-parent 2.2.2.发布 com.example 演示 0.0.1-快照 演示 Spring Boot 演示项目

<properties>
    <java.version>1.8</java.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <scope>runtime</scope>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
        <exclusions>
            <exclusion>
                <groupId>org.junit.vintage</groupId>
                <artifactId>junit-vintage-engine</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>4.1.6.RELEASE</version>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

控制器代码为:

package com.example.demo;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;


public class HelloController {

    @Controller
    @RequestMapping(value = "/test")
    public class TestController {
        @RequestMapping (value="map")
        public String getMeSomething()
        {
            return "Got this from Srini!";
        }
    }
}

DemoApplication 是:

package com.example.demo;

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

@SpringBootApplication
public class DemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }
}

想法?

【问题讨论】:

    标签: java spring spring-boot maven


    【解决方案1】:

    移除spring-web版本 依赖

    Spring Boot 的每个版本都提供了一个精选的依赖项列表 它支持。在实践中,您不需要提供版本 对于构建配置中的任何这些依赖项,如 Spring 引导为您管理。当你升级 Spring Boot 本身时,这些 依赖项也以一致的方式升级。

    See more

    【讨论】:

      【解决方案2】:

      我相信你的 spring 依赖版本中不存在 UriTemplateHandler 类

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

      根据https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/util/UriTemplateHandler.html,它从版本 4.2 开始存在。也许将版本升级到 4.2 会解决您的问题? (下载c的依赖后)。

      【讨论】:

        猜你喜欢
        • 2020-05-12
        • 2015-04-22
        • 1970-01-01
        • 1970-01-01
        • 2015-05-01
        • 1970-01-01
        • 1970-01-01
        • 2015-02-04
        • 2016-11-25
        相关资源
        最近更新 更多