Joa*_*oll 1 spring jsp tomcat classpath
当我将项目作为 Spring Boot 应用程序运行时,我收到此错误,我的猜测是解决方案可能不会太复杂:
错误日志:
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 :
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 :
***************************
APPLICATION FAILED TO START
***************************
Description:
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)
The following method did not exist:
'boolean org.apache.tomcat.util.compat.JreCompat.isGraalAvailable()'
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
Action:
Correct the classpath of your application so that it contains a single, compatible version of org.apache.tomcat.util.compat.JreCompat
Run Code Online (Sandbox Code Playgroud)
POM文件
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 :
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 :
***************************
APPLICATION FAILED TO START
***************************
Description:
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)
The following method did not exist:
'boolean org.apache.tomcat.util.compat.JreCompat.isGraalAvailable()'
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
Action:
Correct the classpath of your application so that it contains a single, compatible version of org.apache.tomcat.util.compat.JreCompat
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
员工阶层
<?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>
Run Code Online (Sandbox Code Playgroud)
EmployeeController类
<%@ 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>
Run Code Online (Sandbox Code Playgroud)
我知道这还没有做太多事情,但我想运行它并打开 http://localhost:8080 并查看结果。
我试图研究其他线程中描述的构建路径库,例如:disableRegistry() does not exist (org.apache.tomcat.util.modeler.Registry),但我不想像我一样弄乱它太多我对此很陌生,任何帮助将不胜感激,谢谢!
tomcat-util您在依赖项中放置了两个不兼容的版本:
tomcat-embed-core,它是 的传递依赖项spring-boot-starter-web,tomcat-jasper,您单独添加。您应该使用embed-tomcat-jasper版本 9.0.43。Maven 试图尽可能地消除版本冲突,但它不知道这一点,tomcat-jasper并且embed-tomcat-jasper是同一回事。由于spring-boot-starter-parent管理 Tomcat 的版本,您可以(并且可能应该)省略版本声明:
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>embed-tomcat-jasper</artifactId>
</dependency>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
15342 次 |
| 最近记录: |