带有TOMCAT 7的RESTEASY的JAX-RS中的异常

时间:2016-05-15 17:46:44

标签: resteasy

我正在尝试使用RESTEASY实现RESTFULL服务。当我尝试在Tomcat Server 7.0中运行时,我得到了异常。请在下面找到详细信息。

错误消息

  

2016年5月15日下午11:10:33 org.jboss.resteasy.core.ExceptionHandler   handleWebApplicationException错误:RESTEASY002010:无法执行   javax.ws.rs.NotFoundException:RESTEASY003210:找不到资源   完整路径:   http://localhost:8080/RestEasyHello/service/HelloRestEasy/response/     在   org.jboss.resteasy.core.registry.ClassNode.match(ClassNode.java:75)     在   org.jboss.resteasy.core.registry.RootClassNode.match(RootClassNode.java:48)     在   org.jboss.resteasy.core.ResourceMethodRegistry.getResourceInvoker(ResourceMethodRegistry.java:445)     在   org.jboss.resteasy.core.SynchronousDispatcher.getInvoker(SynchronousDispatcher.java:254)     在   org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:191)     在   org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:221)     在   org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56)     在   org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51)     在javax.servlet.http.HttpServlet.service(HttpServlet.java:727)at   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)     在   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)     在   org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)     在   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)     在   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)     在   org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)     在   org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)     在   org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503)     在   org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)     在   org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)     在   org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)     在   org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)     在   org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421)     在   org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070)     在   org.apache.coyote.AbstractProtocol $ AbstractConnectionHandler.process(AbstractProtocol.java:611)     在   org.apache.tomcat.util.net.JIoEndpoint $ SocketProcessor.run(JIoEndpoint.java:316)     在   java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)     在   java.util.concurrent.ThreadPoolExecutor中的$ Worker.run(ThreadPoolExecutor.java:615)     在   org.apache.tomcat.util.threads.TaskThread $ WrappingRunnable.run(TaskThread.java:61)     在java.lang.Thread.run(Thread.java:745)

服务代码:

package com.naresh.resteasy;

import javax.ws.rs.GET;
import javax.ws.rs.Produces;
import javax.ws.rs.Consumes;
import javax.ws.rs.Path;

@Path("/HelloResteasy")
@Produces("text/plain")
@Consumes("text/plain")
public class HelloService {

    @GET
    @Path("/response")
    public String printResponse(){
        return "Hello";

    }

}

服务类实现代码

package com.naresh.resteasy;

import java.util.HashSet;
import java.util.Set;

import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;

-------------------------
@ApplicationPath("/service")
public class HelloApplication extends Application {

    private Set<Object> singletons = new HashSet<Object>();

    public HelloApplication() {
        singletons.add(new HelloService());
    }

    @Override
    public Set<Object> getSingletons() {
        return singletons;
    }

}

Web的XML:

    <?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="3.0" 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">
    <display-name>RestEasyHello</display-name>
  <servlet>
    <servlet-name>resteasy-servlet</servlet-name>
    <servlet-class>
            org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher</servlet-class>
    <init-param>
      <param-name>javax.ws.rs.Application</param-name>
      <param-value>com.naresh.resteasy.HelloApplication</param-value>
    </init-param>
  </servlet>
  <servlet-mapping>
    <servlet-name>resteasy-servlet</servlet-name>
    <url-pattern>/*</url-pattern>
  </servlet-mapping>
</web-app>

pom.xml中的依赖项

   <dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-jaxrs</artifactId>
    <version>3.0.13.Final</version>
</dependency>
<!-- Below dependency is for JAXB integration -->
<dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-jaxb-provider</artifactId>
    <version>3.0.13.Final</version>
</dependency>
<dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-servlet-initializer</artifactId>
    <version>3.0.16.Final</version>
</dependency>

有人可以帮忙吗?

1 个答案:

答案 0 :(得分:0)

@Path注释的值是区分大小写的字符串。在您的服务代码中,HelloService使用@Path("/HelloResteasy")进行了注释,但您的请求路径为http://localhost:8080/RestEasyHello/service/HelloRestEasy/response/

@ApplicationPath定义部署中所有JAX-RS服务的相对基本URL路径。因此,在您的代码中,执行时所有JAX-RS RESTful服务都应以/services路径为前缀。也就是http://localhost:8080/service/HelloRestEasy/response/