web-services - 使用 Tomcat 运行 RestEasy Restful Webservice 时出现问题

标签 web-services tomcat tomcat7 resteasy

目前我在尝试使用 Tomcat 运行 RestEasy 时遇到问题。

我添加了所有相应的jar。

但我无法理解导致问题的原因。

下面我给出了所有配置细节和我使用的资源。

服务器:Tomcat 版本 7 我正在使用它。

谁能帮我解决这个问题,如果有什么遗漏请告诉我。

错误日志

9 Sep, 2015 10:30:04 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.30
9 Sep, 2015 10:30:05 PM org.jboss.resteasy.plugins.server.servlet.ConfigurationBootstrap 
WARNING: resteasy.scan is no longer supported.  Use a servlet 3.0 container and the ResteasyServletInitializer
9 Sep, 2015 10:30:06 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
9 Sep, 2015 10:30:06 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
9 Sep, 2015 10:30:06 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 1792 ms
9 Sep, 2015 10:31:15 PM org.jboss.resteasy.core.ExceptionHandler 
SEVERE: failed to execute
javax.ws.rs.NotFoundException: Could not find resource for full path: http://localhost:8080/web-layer/rest/vechicle
    at org.jboss.resteasy.core.registry.ClassNode.match(ClassNode.java:73)
    at org.jboss.resteasy.core.registry.RootClassNode.match(RootClassNode.java:48)
    at org.jboss.resteasy.core.ResourceMethodRegistry.getResourceInvoker(ResourceMethodRegistry.java:444)
    at org.jboss.resteasy.core.SynchronousDispatcher.getInvoker(SynchronousDispatcher.java:255)
    at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:192)
    at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:220)
    at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56)
    at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51)

库配置

WebContent\WEB-INF\lib\activation-1.1.1.jar
WebContent\WEB-INF\lib\commons-codec-1.6.jar
WebContent\WEB-INF\lib\commons-io-2.1.jar
WebContent\WEB-INF\lib\commons-logging-1.1.3.jar
WebContent\WEB-INF\lib\httpclient-4.3.6.jar
WebContent\WEB-INF\lib\httpcore-4.3.3.jar
WebContent\WEB-INF\lib\jaxrs-api-3.0.12.Final.jar
WebContent\WEB-INF\lib\jboss-annotations-api_1.1_spec-1.0.1.Final.jar
WebContent\WEB-INF\lib\jcip-annotations-1.0.jar
WebContent\WEB-INF\lib\resteasy-jaxrs-3.0.12.Final.jar

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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 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>asf-lpa-web</display-name>

  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>

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

    <!-- this need same with resteasy servlet url-pattern -->
    <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>

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

</web-app>

服务接口(interface)

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 interface ParkService {

        @GET
        @Path("/vechicle")
        @Produces(MediaType.APPLICATION_JSON)
        public  Response getViewPark();

    }

服务实现类

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

import javax.ws.rs.core.Response;

public class ParkServiceImpl implements ParkService{

    public Response getViewPark(){

        ViewTo viewTo = new ViewTo();
        //
        ///
        ///

        return response("view",viewTo);

    }

    private Response response(String jsonName, Object object) {

        Map<String, Object> outputMap = new TreeMap<String, Object>();
        outputMap.put(jsonName, object);

        return Response.ok(outputMap).build();
    }

}

最佳答案

您可能面临与创建此问题的用户相同的问题:javax.ws.rs.NotFoundException: Could not find resource for full path

首先尝试将您的 rest api 版本更改为 3.0.4.Final,如果您的应用可以使用它,那么肯定是同样的问题。

关于web-services - 使用 Tomcat 运行 RestEasy Restful Webservice 时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32486019/

相关文章:

java - 尝试将 Spring 应用程序部署到 Tomcat

tomcat - tomcat 7中的类加载

c++ - 一个好的 SOAP 的 C++ 库

tomcat - jwchat 与 tomcat 上的 opnefire 集成?

tomcat - 将请求路由到微服务架构中相关服务的方法

tomcat - 在 tomcat 中,如何在服务器端启用 gzip 配置后默认返回没有 gzip 压缩的原始响应负载?

无法理解 WCF MustUnderstand header

java - SOAP 消息不得包含文档类型声明 (DTD)

vb.net - (407) 需要代理身份验证(ISA 服务器需要授权才能完成请求。拒绝访问 Web 代理筛选器。)

tomcat - 如何在 Tomcat 7 上实现 Socket.io