小编Ant*_*Ant的帖子

异常处理 errorPage[errorCode=0, location=/error]

我的 Spring Boot 项目曾经在 Mac 上运行良好。今天我将代码拉到我的 Windows 圈上,然后出现问题,当出现错误(如 404、500)时,显示的是 Tomcat 错误页面,而不是我的自定义错误页面。与此同时,后端报错:

2019-03-22 23:55:18.659 ERROR 11000 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost]           :Exception Processing ErrorPage[errorCode=0, location=/error]**

java.lang.NoSuchMethodError: javax.servlet.http.HttpServletRequest.getHttpServletMapping()Ljavax/servlet/http/HttpServletMapping;
Run Code Online (Sandbox Code Playgroud)

Spring Boot版本为2.1.13,使用依赖为:

plugins {
    id 'org.springframework.boot' version '2.1.3.RELEASE'
    id 'java'
}

apply plugin: 'io.spring.dependency-management'
apply plugin: 'project-report'

group = 'cn.itscloudy'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'

    testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
Run Code Online (Sandbox Code Playgroud)

这是一个简单的演示,依赖项仅包含 web 和 thymeleaf。

位于error.html路径下resources/template

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Error</title>
</head>
<body>
<h1>Error Page</h1> …
Run Code Online (Sandbox Code Playgroud)

java spring spring-boot

6
推荐指数
1
解决办法
2万
查看次数

标签 统计

java ×1

spring ×1

spring-boot ×1