带有 WildFly 的 JavaEE:未找到 Rest 资源 - 为什么?
JavaEE with WildFly: Rest Resource not found - why?
我正在尝试 运行 只是一个简单的 REST 应用程序,后台带有 WildFly-Application Server。但是 REST-Call 永久地给我 Not Found
-Error.
这是我的 RestService
-class:
@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>
web.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>
和我的项目结构:
我想通过以下方式调用我的 Rest-Service url:
http://127.0.0.1:8080/services/rest/hello
但它给出了未找到错误 - 这是什么问题?
我发现错误:
项目结构错误:必须是 web
而不是 webapp
。
我正在尝试 运行 只是一个简单的 REST 应用程序,后台带有 WildFly-Application Server。但是 REST-Call 永久地给我 Not Found
-Error.
这是我的 RestService
-class:
@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>
web.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>
和我的项目结构:
我想通过以下方式调用我的 Rest-Service url:
http://127.0.0.1:8080/services/rest/hello
但它给出了未找到错误 - 这是什么问题?
我发现错误:
项目结构错误:必须是 web
而不是 webapp
。