Java休息服务404ing

时间:2016-12-01 01:29:51

标签: java rest maven amazon-web-services tomcat

我尝试创建和部署一个restful Web Service,但是在部署时我无法调用任何方法。 我试图在AWS上部署它' Elastic Beanstalk,但是在部署时我无法访问欢迎页面之外的任何资源。

Netbeans识别方法,并将显示方法,(在这种情况下是一个简单的hello world方法,向用户返回一个字符串,告诉你好),如果我查看AWS访问日志,服务器正在接收请求,他们会不要看起来畸形。

它是一个在Tomcat 8上运行的Maven Web服务,我通过使用多个教程生成了以下内容,但是总是遇到无法调用该方法的相同问题,因为它只会导致404。

日志示例:

<?xml version="1.0" encoding="UTF-8"?>

<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">

<servlet>
    <servlet-name>Jersey Web Application</servlet-name>
    <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>Jersey Web Application</servlet-name>
    <url-pattern>/test/*</url-pattern>
</servlet-mapping>
<session-config>
    <session-timeout>
        30
    </session-timeout>
</session-config>

部署链接:
http://sample-env-3.3ryvtqr8zj.eu-west-1.elasticbeanstalk.com

项目结构:
http://i.imgur.com/vGWBBqE.png

Web.xml中:

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>My First JSP Page</title>
</head>
<body>
    <h1>Hello World!</h1>
</body>

Index.jsp(最可能无关紧要,但无论如何都包括在内):

package com.mycompany.testdeployaws;

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("/h")
public class test {
@GET
@Produces({MediaType.APPLICATION_JSON})
public String helloWorld(){
    return "Hello world";

}
}

test.java:

<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.mycompany</groupId>
<artifactId>TestDeployAWS</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>

<name>TestDeployAWS</name>

<properties>
    <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-web-api</artifactId>
        <version>6.0</version>
        <scope>provided</scope>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
                <compilerArguments>
                    <endorseddirs>${endorsed.dir}</endorseddirs>
                </compilerArguments>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.1.1</version>
            <configuration>
                <failOnMissingWebXml>false</failOnMissingWebXml>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>2.1</version>
            <executions>
                <execution>
                    <phase>validate</phase>
                    <goals>
                        <goal>copy</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${endorsed.dir}</outputDirectory>
                        <silent>true</silent>
                        <artifactItems>
                            <artifactItem>
                                <groupId>javax</groupId>
                                <artifactId>javaee-endorsed-api</artifactId>
                                <version>6.0</version>
                                <type>jar</type>
                            </artifactItem>
                        </artifactItems>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

最后,pom.xml因为它是一个Maven构建:

Aborted_connects         | 4
Created_tmp_disk_tables  | 64
Handler_read_rnd         | 2.2 k
Handler_read_rnd_next    | 149.8 k
Innodb_buffer_pool_reads | 1.1 k    
Key_reads                | 242
Opened_tables            | 198
Qcache_free_blocks       | 1
Slow_queries             | 14
Sort_merge_passes        | 1

0 个答案:

没有答案