通过这段短视频提供我所采取的每一步:https://youtu.be/hbSr8sRYuOk
项目代码在这里:https://github.com/LJonn/restapiHelloWorld
在 tomcat 上的本地服务器上运行所有内容。
我遇到这个问题已经有一段时间了,并且不知道问题可能出在哪里......
我尝试了如下 URL:“http://localhost:8080/api/hello”和“http://localhost:8080/helloworld/api/hello”,并期望其中之一能够工作。
运行 http://localhost:8080/manager/text/list 显示 helloworld.war 已部署正常并正常工作:
OK - Listed applications for virtual host [localhost]
/:running:0:ROOT
/helloworld:running:0:helloworld
/examples:running:0:examples
/host-manager:running:0:host-manager
/manager:running:0:manager
/docs:running:0:docs
那么为什么我仍然收到 HTTP Status 404 页面呢?我可以尝试做什么来找到问题?
这些是我的项目的 Maven 依赖项:
<dependencies>
<dependency>
<groupId>jakarta.platform</groupId>
<artifactId>jakarta.jakartaee-web-api</artifactId>
<version>9.1.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
感谢 Nikos Paraskevopoulos 的评论,看起来从 Tomcat 更改为 TomEE 可能会解决该问题,但现在我遇到了 .war 文件无法部署/启动的问题,可能是某种版本兼容性问题,tomcat 管理器尝试启动 .war 文件时 GUI 给出此错误:
FAIL - Application at context path [/helloworld] could not be started
FAIL - Encountered exception [org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/helloworld]]]
查看管理器日志看起来它与注释和 Java 16 可能有关?:
...
Caused by: java.lang.IllegalArgumentException: Unsupported class file major version 60
at org.apache.xbean.asm7.ClassReader.<init>(ClassReader.java:195)
at org.apache.xbean.asm7.ClassReader.<init>(ClassReader.java:176)
at org.apache.xbean.asm7.ClassReader.<init>(ClassReader.java:162)
at org.apache.xbean.asm7.ClassReader.<init>(ClassReader.java:283)
at org.apache.xbean.finder.AnnotationFinder.readClassDef(AnnotationFinder.java:1176)
... 52 more
01-Sep-2021 15:25:02.185 INFO [http-nio-8080-exec-3] org.apache.catalina.core.ApplicationContext.log HTMLManager: list: Listing contexts for virtual host 'localhost'
我尝试检查 Eclipse 上的 JRE 版本,它是 16.0.2,在我看来,tomcat 上运行的是相同的版本。