无法呼叫RestEasy Url

时间:2015-07-27 03:34:18

标签: rest maven java-ee

我是RestFul API的新手。我有一个使用Maven的示例项目。我正在使用Jboss服务器进行部署。

问题是文件已部署,但当我尝试访问URl时,它显示404错误

url:http://localhost:8080/RESTEasy/rest/RESTEasyHelloWorld/data

控制台

中没有错误

以下是我的档案:
的pom.xml

 <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>com.rest</groupId>
    <artifactId>RESTEasy</artifactId>
    <version>0.0.1-SNAPSHOT</version>

    <repositories>
        <repository>
            <id>JBoss repository</id>
            <url>https://repository.jboss.org/nexus/content/groups/public-jboss/</url>
        </repository>
    </repositories>
    <dependencies>
        <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>resteasy-jaxrs</artifactId>
            <version>3.0.4.Final</version>
        </dependency>
    </dependencies>
</project>

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_3_0.xsd"
    id="WebApp_ID" version="3.0">
    <display-name>RESTEasy</display-name>

    <servlet-mapping>
        <servlet-name>resteasy-servlet</servlet-name>
        <url-pattern>/rest/*</url-pattern>
    </servlet-mapping>

    <!-- Auto scan REST service -->
    <context-param>
        <param-name>resteasy.scan</param-name>
        <param-value>true</param-value>
    </context-param>

    <!-- this should be the same URL pattern as the servlet-mapping property -->
    <context-param>
        <param-name>resteasy.servlet.mapping.prefix</param-name>
        <param-value>/rest</param-value>
    </context-param>

    <listener>
        <listener-class>
            org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap
            </listener-class>
    </listener>

    <servlet>
        <servlet-name>resteasy-servlet</servlet-name>
        <servlet-class>
            org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher
        </servlet-class>
    </servlet>

</web-app>

Rest Java file:

package com.rest;


import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.Response;

@Path("/RESTEasyHelloWorld")
public class RESTEasyHelloWorldService {

    @GET
    @Path("/{pathParameter}")
    public Response responseMsg( @PathParam("pathParameter") String pathParameter
            ) {

        String response = "Hello from: " + pathParameter;

        return Response.status(200).entity(response).build();
    }
}

服务器日志:

 08:51:54,288 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-6) JBAS015876: 
Starting deployment of "RESTEasy-0.0.1-SNAPSHOT.jar" (runtime-name: "RESTEasy-0.0.1-SNAPSHOT.jar")

        08:51:54,300 INFO  [org.jboss.as.server] (DeploymentScanner-threads - 1) JBAS018565: 
    Replaced deployment "RESTEasy-0.0.1-SNAPSHOT.jar" with deployment "RESTEasy-0.0.1-SNAPSHOT.jar"

1 个答案:

答案 0 :(得分:0)

  1. 应用程序需要部署在战争中(使用正确的webapp结构)而不是jar。

  2. 如果您不更改最终名称,则战争将具有-0.0.1-SNAPSHOT后缀,路径中将需要该后缀。您可以将<finalName>${project.artifactId}</finalName>添加到pom中的<build>,这样就可以使战争成为项目名称