java - 带有 WildFly 的 JavaEE:未找到剩余资源 - 为什么?
问题描述
我试图在后台运行一个带有 WildFly-Application Server 的简单 REST-Application。但是 REST-Call 给了我永久的Not Found
错误。
这是我的RestService
班级:
@Path("/rest")
public class RestService {
@GET
@Path("/hello")
@Produces(MediaType.TEXT_PLAIN)
public Response helloWorld() {
try {
System.out.println("ABCDEF");
return Response.status(Response.Status.OK).entity("hello world!").build();
} catch (Throwable throwable) {
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(throwable).build();
}
}
}
使用 Rest-Configuration-File :
@ApplicationPath("/")
public class JaxRsActivator extends Application {
}
这是我的配置文件:
pom.xml:
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.java</groupId>
<artifactId>JavaEE</artifactId>
<version>1.0</version>
<packaging>war</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>9</maven.compiler.source>
<maven.compiler.target>9</maven.compiler.target>
</properties>
<build>
<finalName>javaee</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.0</version>
</plugin>
</plugins>
</build>
网页.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<display-name>REST</display-name>
</web-app>
jboss-web.xml:
<jboss-web>
<context-root>services</context-root>
</jboss-web>
和我的项目结构:
我想通过以下 url 调用我的 Rest-Service:
http://127.0.0.1:8080/services/rest/hello
但它给出了 Not Found-Error - 这里有什么问题?
解决方案
我发现了错误:
项目结构错误:必须是web
而不是webapp
。
推荐阅读
- javascript - JavaScript 模板字符串不显示我的值
- jquery - 使用 Laravel 8 Livewire 组件更新图像
- java - Gradle 不再解决我的依赖关系 - 但是设置了存储库
- python - SQLite3 和 Python:为什么我的表格不打印?
- postgresql - 如何从连接表中获取列的最大值?
- python - 当没有下载链接但有一个javascript按钮时如何使用Python从网站下载文件
- algorithm - 根据维基百科,为什么冒泡排序的总空间复杂度为 O(1)?
- python - 如何将 x 和 y 像素的颜色更改为蓝色?
- mysql - 如何将数据集中的所有空值更新为 0
- python - 生成模拟外汇或股票 OHLC 数据以用于熊猫问题的可重现示例