[英]I'm using JakartaEE and making a "hello world" kind of restfulAPI, can't get a return string by visiting URL
Providing every step I took with this short video: https://youtu.be/hbSr8sRYuOk提供我用这个短视频采取的每一步: https://youtu.be/hbSr8sRYuOk
Project code here: https://github.com/LJonn/restapiHelloWorld项目代码在这里: https://github.com/LJonn/restapiHelloWorld
Running everything on a local server on tomcat.在 tomcat 上的本地服务器上运行所有内容。
I'm having this issue for quite some time and ran out of ideas where the problem might be... I tried URL's such as these: "http://localhost:8080/api/hello" and "http://localhost:8080/helloworld/api/hello" and expected one of these to work.我遇到这个问题已经有一段时间了,我想不出问题出在哪里……我试过这样的 URL:“http://localhost:8080/api/hello”和“http://localhost :8080/helloworld/api/hello" 并期望其中之一可以工作。
Running http://localhost:8080/manager/text/list shows that helloworld.war is deployed fine and working:运行 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
So why I still get a HTTP Status 404 page?那么为什么我仍然得到 HTTP 状态 404 页面? What could I try to do to find the issue?
我该怎么做才能找到问题所在?
These are my project's Maven dependencies:这些是我项目的 Maven 依赖项:
<dependencies>
<dependency>
<groupId>jakarta.platform</groupId>
<artifactId>jakarta.jakartaee-web-api</artifactId>
<version>9.1.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
Thanks to Nikos Paraskevopoulos comment it looks like changing from Tomcat to TomEE might fix the issue, but now I'm running into a problem where the.war file can't be deployed/started, probably some sort of versions compatibility issue, tomcat manager GUI gives this error when trying to start the.war file:感谢 Nikos Paraskevopoulos 的评论,看起来从 Tomcat 更改为 TomEE 可能会解决问题,但现在我遇到了无法部署/启动 .war 文件的问题,可能是某种版本兼容性问题,tomcat 经理GUI 在尝试启动 .war 文件时出现此错误:
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]]]
Looking to manager logs It looks like it has something to do with annotations and Java 16 maybe?:查看管理器日志看起来它与注释和 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'
I've tried to check JRE version on Eclipse and it's 16.0.2 and it looks to me that the same version is running on tomcat.我试图检查 Eclipse 上的 JRE 版本,它是 16.0.2,在我看来,相同的版本正在 tomcat 上运行。
Tomcat 10.0 and 10.1 are not full Jakarta EE 9.1 application servers: you shouldn't use the jakarta.jakartaee-web-api
artifact, which would imply that the runtime supports all Jakarta EE 9.1 Web Profile technologies. Tomcat 10.0 和 10.1不是完整的 Jakarta EE 9.1 应用程序服务器:您不应使用
jakarta.jakartaee-web-api
工件,这意味着运行时支持所有 Jakarta EE 9.1 Web Profile技术。
Tomcat does not implement all the specs required in Web Profile . Tomcat 没有实现Web Profile中要求的所有规范。 At least four other products do.
至少还有四种其他产品。 See this list for Jakarta Web Profile 9.1:
请参阅此列表以了解 Jakarta Web Profile 9.1:
You can find the list of supported technologies on Tomcat's web site and for Tomcat 10 they translate to this list shown as a Maven POM snippet.您可以在Tomcat 的 web 站点上找到支持的技术列表,对于 Tomcat 10,它们将转换为此列表,显示为Maven POM片段。
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<version>5.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jakarta.servlet.jsp</groupId>
<artifactId>jakarta.servlet.jsp-api</artifactId>
<version>3.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jakarta.el</groupId>
<artifactId>jakarta.el-api</artifactId>
<version>4.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jakarta.websocket</groupId>
<artifactId>jakarta.websocket-api</artifactId>
<version>2.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jakarta.security.auth.message</groupId>
<artifactId>jakarta.security.auth.message-api</artifactId>
<version>2.0.0-RC1</version>
<scope>provided</scope>
</dependency>
Since Servlet 3.0, additional Jakarta EE specifications can be added using the servlet pluggability mechanism .从 Servlet 3.0 开始,可以使用servlet 可插入性机制添加额外的 Jakarta EE 规范。 To use JAX-RS you need to add:
要使用 JAX-RS,您需要添加:
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<version>3.0.2</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
<version>3.0.2</version>
</dependency>
or an equivalent configuration using other JAX-RS implementations.或使用其他 JAX-RS 实现的等效配置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.