更正应用程序的类路径,使其包含 org.apache.tomcat.util.compat.JreCompat 的单个兼容版本.使用jsp文件 [英] Correct the classpath of your application so that it contains a single, compatible version of org.apache.tomcat.util.compat.JreCompat. Using jsp file
问题描述
在将我的项目作为 Spring Boot 应用程序运行时出现此错误,我猜解决方案可能不会太复杂:
I get this error when running my project as a Spring Boot App, my guess is that the solution might not be too complicated:
错误日志:
2021-03-05 12:53:10.041 INFO 4704 --- [ main] .s.M13SimpleSpringHttpServiceApplication :未设置活动配置文件,回退到默认配置文件:默认2021-03-05 12:53:10.936 INFO 4704 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate :在默认模式下引导 Spring Data JPA 存储库.2021-03-05 12:53:10.954 INFO 4704 --- [main] .s.d.r.c.RepositoryConfigurationDelegate:在 7 毫秒内完成 Spring Data 存储库扫描.找到 0 个 JPA 存储库接口.2021-03-05 12:53:11.520 WARN 4704 --- [main] ConfigServletWebServerApplicationContext:上下文初始化期间遇到异常 - 取消刷新尝试:org.springframework.context.ApplicationContextException:无法启动 Web 服务器;嵌套异常是 java.lang.NoSuchMethodError: 'boolean org.apache.tomcat.util.compat.JreCompat.isGraalAvailable()'2021-03-05 12:53:11.531 INFO 4704 --- [主要] ConditionEvaluationReportLoggingListener :
2021-03-05 12:53:10.041 INFO 4704 --- [ main] .s.M13SimpleSpringHttpServiceApplication : No active profile set, falling back to default profiles: default 2021-03-05 12:53:10.936 INFO 4704 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode. 2021-03-05 12:53:10.954 INFO 4704 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 7 ms. Found 0 JPA repository interfaces. 2021-03-05 12:53:11.520 WARN 4704 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is java.lang.NoSuchMethodError: 'boolean org.apache.tomcat.util.compat.JreCompat.isGraalAvailable()' 2021-03-05 12:53:11.531 INFO 4704 --- [ main] ConditionEvaluationReportLoggingListener :
启动 ApplicationContext 时出错.要显示条件报告,请在启用调试"的情况下重新运行您的应用程序.2021-03-05 12:53:11.552 错误 4704 --- [主要] o.s.b.d.LoggingFailureAnalysisReporter :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled. 2021-03-05 12:53:11.552 ERROR 4704 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
应用程序无法启动
说明:
试图调用不存在的方法.尝试是从以下位置进行的:
An attempt was made to call a method that does not exist. The attempt was made from the following location:
org.apache.catalina.startup.Tomcat.<clinit>(Tomcat.java:1303)
以下方法不存在:
'boolean org.apache.tomcat.util.compat.JreCompat.isGraalAvailable()'
该方法的类 org.apache.tomcat.util.compat.JreCompat 可从以下位置获得:
The method's class, org.apache.tomcat.util.compat.JreCompat, is available from the following locations:
jar:file:/C:/Users/xxxx/.m2/repository/org/apache/tomcat/tomcat-util/8.5.30/tomcat-util-8.5.30.jar!/org/apache/tomcat/util/compat/JreCompat.class
jar:file:/C:/Users/xxxx/.m2/repository/org/apache/tomcat/embed/tomcat-embed-core/9.0.43/tomcat-embed-core-9.0.43.jar!/org/apache/tomcat/util/compat/JreCompat.class
从以下位置加载了类层次结构:
The class hierarchy was loaded from the following locations:
org.apache.tomcat.util.compat.JreCompat: file:/C:/Users/xxxx/.m2/repository/org/apache/tomcat/tomcat-util/8.5.30/tomcat-util-8.5.30.jar
操作:
更正应用程序的类路径,使其包含一个兼容版本的 org.apache.tomcat.util.compat.JreCompat
Correct the classpath of your application so that it contains a single, compatible version of org.apache.tomcat.util.compat.JreCompat
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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.3</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.simpleSpringHTTPService</groupId>
<artifactId>M13SimpleSpringHTTPService</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>M13SimpleSpringHTTPService</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jasper</artifactId>
<version>8.5.30</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
里面的jsp文件:src/main/webApp文件夹
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<form action="addEmployee">
<input type="text" name="id"><br>
<input type="text" name="first_name"><br>
<input type="text" name="last_name"><br>
<input type="text" name="job_role"><br>
<input type="submit"><br>
</form>
</body>
</html>
员工类
package com.simpleSpringHTTPService.model;
public class Employee {
private String first_name;
private String last_name;
private String job_role;
private int id;
public String getFirst_name() {
return first_name;
}
public void setFirst_name(String first_name) {
this.first_name = first_name;
}
public String getLast_name() {
return last_name;
}
public void setLast_name(String last_name) {
this.last_name = last_name;
}
public String getJob_role() {
return job_role;
}
public void setJob_role(String job_role) {
this.job_role = job_role;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
@Override
public String toString() {
return "Employee [first_name=" + first_name + ", last_name=" + last_name + ", job_role=" +
job_role + ", id="+ id + "]";
}
}
EmployeeController 类
package com.simpleSpringHTTPService.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class EmployeeController {
@RequestMapping("/")
public String home() {
return "home.jsp";
}
}
我知道这还没有做太多,但我想运行它并打开 http://localhost:8080 并查看结果.
I am aware that this does not do much yet, but I would like to run it and open http://localhost:8080 and see the result.
我尝试查看其他线程中描述的构建路径库,例如:disableRegistry() 不存在(org.apache.tomcat.util.modeler.Registry),但我不想过多地弄乱它,因为我是新手,任何帮助将不胜感激,谢谢!
I have tried to look into the buildpath libraries as described in other threads like: disableRegistry() doesn't exist (org.apache.tomcat.util.modeler.Registry), but i would not want to mess with it too much as I am new to this, any help would be much appreciated, thanks!
推荐答案
您在依赖项中放置了两个不兼容的 tomcat-util
版本:
You put two incompatible versions of tomcat-util
among your dependencies:
- 版本 9.0.43 包含在
tomcat-embed-core
,它是spring-boot-starter-web
, - 版本 8.5.30 是 <的传递依赖项code>tomcat-jasper,您单独添加的.
您应该使用 embed-tomcat-jasper
代替,版本 9.0.43.Maven 试图尽可能地消除版本冲突,但它不知道 tomcat-jasper
和 embed-tomcat-jasper
是一回事.
You should use embed-tomcat-jasper
instead, version 9.0.43. Maven tries to eliminate version conflicts as best as it can, but it doesn't know that tomcat-jasper
and embed-tomcat-jasper
are the same thing.
这篇关于更正应用程序的类路径,使其包含 org.apache.tomcat.util.compat.JreCompat 的单个兼容版本.使用jsp文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!