我想用RESTEASY實現RESTFULL服務。當我嘗試在Tomcat Server 7.0中運行時,iam得到異常。請在下面找到詳細信息。JAX-RS與RESTEASY與TOMCAT 7的異常
錯誤消息
May 15, 2016 11:10:33 PM org.jboss.resteasy.core.ExceptionHandler handleWebApplicationException ERROR: RESTEASY002010: Failed to execute javax.ws.rs.NotFoundException: RESTEASY: Could not find resource for full path: http://localhost:8080/RestEasyHello/service/HelloRestEasy/response/ at org.jboss.resteasy.core.registry.ClassNode.match(ClassNode.java:75) at org.jboss.resteasy.core.registry.RootClassNode.match(RootClassNode.java:48) at org.jboss.resteasy.core.ResourceMethodRegistry.getResourceInvoker(ResourceMethodRegistry.java:445) at org.jboss.resteasy.core.SynchronousDispatcher.getInvoker(SynchronousDispatcher.java:254) at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:191) at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:221) at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56) at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51) at javax.servlet.http.HttpServlet.service(HttpServlet.java:727) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at 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>
是否有人可以在這方面的幫助?
謝謝拉赫曼的迴應。我嘗試了正確的資源URL,但得到相同的異常。 2016年5月16日12:50:56 org.jboss.resteasy.core.ExceptionHandler handleWebApplicationException 錯誤:RESTEASY002010:無法執行 javax.ws.rs.NotFoundException:RESTEASY:找不到完整路徑的資源:http://localhost:8080/RestEasyHello/service/HelloResteasy/response/ \t at org.jboss.resteasy.core.registry.ClassNode.match(ClassNode.java:75) –
@NareshKumar查看我的更新 – taoxiaopang