JavaEE与WildFly:未找到Rest资源-为什么?
我正试图在后台运行一个简单的REST应用程序和WildFly应用服务器。但是REST调用给我永久性的JavaEE与WildFly:未找到Rest资源-为什么?,java,rest,jakarta-ee,wildfly,Java,Rest,Jakarta Ee,Wildfly,我正试图在后台运行一个简单的REST应用程序和WildFly应用服务器。但是REST调用给我永久性的notfound-错误 这是我的RestService-类: @Path("/rest") public class RestService { @GET @Path("/hello") @Produces(MediaType.TEXT_PLAIN) public Response helloWorld() { try {
notfound
-错误
这是我的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配置文件:
@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>
4.0.0
org.java
我想通过以下url调用我的Rest服务:
但它给出了未发现的错误-问题出在哪里?我发现了错误:
项目结构错误:它必须是web
,而不是webapp
应用程序服务器是否配置为在本地主机上运行?服务器日志是否表明应用程序已成功部署?您能否访问.war中的任何其他资源(如静态文件、jsp、servlet)?是否http://127.0.0.1:8080/services
returnindex.html
?您正在使用的服务器配置文件中是否启用了jax rs?是的,它返回index.html-web页面…是的,server.logs显示:[2018-04-29 07:36:01198]Artifact JavaEE:war:Artifact已成功部署…我如何发现是否启用了jax rs?
<?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>
<context-root>services</context-root>
</jboss-web>