休息服务在本地而不是在aws上调用

时间:2016-03-28 06:05:19

标签: java amazon-web-services elastic-beanstalk jersey-2.0

我使用Jersey 2.0 REST API创建了一个Web应用程序。它在我的本地计算机上工作得很好但是当我在AWS上部署我的应用程序时,RESTFul服务没有被调用。

以下是情景:

以下服务网址在我的本地计算机上运行正常。我的应用的上下文路径是/ testrest。

http://localhost:8080/testrest/test/rest

enter image description here

在AWS(Tomcat 8 Java 8)上部署时,下面的代码不起作用,并且给出了404错误:

http://testrest.wm5zqpd6m2.ap-southeast-1.elasticbeanstalk.com/testrest/rest/test

但有趣的是,如果我删除了testrest这个词,并点击下面的url就会返回成功的回复。 Plz尝试点击链接并查看结果。我附加了我的pom.xml,web.xml和我的资源类。

http://testrest.wm5zqpd6m2.ap-southeast-1.elasticbeanstalk.com/rest/test

的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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>test.rest</groupId>
  <artifactId>testrest</artifactId>
  <packaging>war</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <name>testrest Maven Webapp</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>

    <dependency>
            <groupId>javax.ws.rs</groupId>
            <artifactId>javax.ws.rs-api</artifactId>
            <version>2.0</version>
        </dependency>

        <dependency>
            <groupId>org.glassfish.jersey.containers</groupId>
            <artifactId>jersey-container-servlet-core</artifactId>
            <version>2.6</version>
        </dependency>

        <dependency>
            <groupId>org.glassfish.jersey.core</groupId>
            <artifactId>jersey-server</artifactId>
            <version>2.6</version>
        </dependency>

        <dependency>
            <groupId>org.glassfish.jersey.bundles</groupId>
            <artifactId>jaxrs-ri</artifactId>
            <version>2.6</version>
        </dependency>

  </dependencies>
  <build>
    <finalName>testrest</finalName>

    <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.0</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.6</version>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>
        </plugins>

  </build>
</project>

Web.xml中

<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
          http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    version="3.0">

  <display-name>Archetype Created Web Application</display-name>

  <servlet>
    <servlet-name>Jersey REST Service</servlet-name>
    <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
    <init-param>
        <param-name>jersey.config.server.provider.packages</param-name>
        <param-value>
            com.testing
        </param-value>
    </init-param>

    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>Jersey REST Service</servlet-name>
    <url-pattern>/rest/*</url-pattern>

  </servlet-mapping>
</web-app>

资源类:

package com.testing;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

@Path("/")
public class TestRest {

    @GET
    @Produces(MediaType.APPLICATION_JSON)
    @Path("/test")
    public Response testRest(){

        return Response.ok("Success Again and Again", MediaType.APPLICATION_JSON).build();
    }

}

0 个答案:

没有答案