Netbeans - Tomcat的Restful Service导致404

时间:2017-06-15 17:22:03

标签: java rest tomcat netbeans

没有为此找到解决方案(并尝试至少5个小时......):

我使用Tomcat 8.0.27.0和Jersey 2.5.1(JAX-RS RI)并创建了一个简单的Restful-Webservice,它与Glassfish一起工作正常,但尝试使用Tomcat会导致404 - 找不到文件(The请求的资源不可用。)

ApplicationConfig.java

package com.example;

import java.util.Set;
import javax.ws.rs.core.Application;

@javax.ws.rs.ApplicationPath("/webresources")
public class ApplicationConfig extends Application {

@Override
public Set<Class<?>> getClasses() {
    Set<Class<?>> resources = new java.util.HashSet<>();
    addRestResourceClasses(resources);
    return resources;
}

/**
 * Do not modify addRestResourceClasses() method.
 * It is automatically populated with
 * all resources defined in the project.
 * If required, comment out calling this method in getClasses().
 */
private void addRestResourceClasses(Set<Class<?>> resources) {
    resources.add(com.example.ServiceResource.class);
}}

ServiceResource.java

@Path("/service")
public class ServiceResource {

    @Context
    private UriInfo context;

    public ServiceResource() {
    }

    @GET
    @Path("/{param}")
    @Produces("text/html")
    public Response getHtml(@PathParam("param") String message) {
         String output = "Hello " + message + "!";
         return Response.status(200).entity(output).build();
    }

    @PUT
    @Consumes("text/html")
    public void putHtml(String content) {
    }
}

我尝试打开所有可能的类型,但希望它可以在http://localhost:8080/contextname/webresources/service上运行。 基本路径http://localhost:8080/contextname正在运行。

任何人都知道为什么它与Glassfish一起工作正常而不是Tomcat?谢谢到目前为止!

0 个答案:

没有答案
相关问题