javax.ws.rs.NotFoundException:RESTEASY003210:找不到完整路径的资源:使用 RestEASY、Intellij IDEA 16.1、Tomcat 8.0.33
javax.ws.rs.NotFoundException: RESTEASY003210: Could not find resource for full path: using RestEASY, Intellij IDEA 16.1, Tomcat 8.0.33
有人问了很多这样的问题,但我已经尝试了所有建议的变体,用谷歌搜索了我的问题,检查了 RestEASY 规范。什么都帮不了我。
我正在创建一种非常简单的 "Hello World" 应用程序。当我编写路由到我的 REST 服务的 URL 时,我收到以下错误和浏览器中的空白页面。
这是堆栈跟踪:
15-May-2016 14:41:58.977 ERROR [http-nio-8080-exec-5] org.jboss.resteasy.core.ExceptionHandler.handleWebApplicationException RESTEASY002010: Failed to execute
javax.ws.rs.NotFoundException: RESTEASY003210: Could not find resource for full path: http://localhost:8080/api/v1/status
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:257)
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:194)
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:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:522)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1095)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:672)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1502)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1458)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
这是我的pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<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.taras.resty</groupId>
<artifactId>Resty</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxrs</artifactId>
<version>LATEST</version>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>LATEST</version>
</dependency>
</dependencies>
</project>
这是我的web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<servlet>
<servlet-name>V1_Status</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.taras.resty.status.V1_Status</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>V1_Status</servlet-name>
<url-pattern>/api/*</url-pattern>
</servlet-mapping>
</web-app>
这是处理我的 REST 请求的 class:
package com.taras.resty.status;
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.Application;
import javax.ws.rs.ApplicationPath;
@ApplicationPath("/v1/status")
public class V1_Status extends Application {
private static final String api_version= "00.01.00";
@GET
@Produces(MediaType.TEXT_HTML)
public String returnTitle(){
return "<p>Java Web Service</p>";
}
@Path("/version")
@GET
@Produces(MediaType.TEXT_HTML)
public String returnVersion(){
return "<p>Version + </p>" + api_version;
}
}
我使用的URL是:http://localhost:8080/api/v1/status
提前谢谢你。
编辑 - 已解决 对于将面临同样问题的人。 @tair 在解决我的错误方面帮助了我很多。试试他的版本(你可以在这里找到它 https://github.com/tsabirgaliev/hello-jaxrs)。
我们还没有找到原因,它不知何故消失了(魔法)。
当然,有关更详细的信息,请查看规范
http://docs.jboss.org/resteasy/docs/3.0.16.Final/userguide/html_single/index.html#d4e113
正如您的 web.xml 建议您使用的是 Servlets 3.1 兼容 Tomcat,Resteasy 的配置应该不同。请参考 Resteasy 官方文档 [1] 的 3.5. Standalone Resteasy in Servlet 3.0 Containers
部分。
如果您坚持旧式配置,您应该将 JAX-RS 应用程序指定为 init-param
for HttpServletDispatcher
:
<servlet>
<servlet-name>Resteasy</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.taras.resty.Application</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>V1_Status</servlet-name>
<url-pattern>/api/*</url-pattern>
</servlet-mapping>
<context-param>
<param-name>resteasy.servlet.mapping.prefix</param-name>
<param-value>/api</param-value>
</context-param>
无论哪种情况,您都必须继承 javax.ws.rs.Application
.
更新:这里 [2] 是一个完整的应用示例。使用 Tomcat 8.0.33
测试
[1] http://docs.jboss.org/resteasy/docs/3.0.16.Final/userguide/html_single/index.html#d4e113
有人问了很多这样的问题,但我已经尝试了所有建议的变体,用谷歌搜索了我的问题,检查了 RestEASY 规范。什么都帮不了我。 我正在创建一种非常简单的 "Hello World" 应用程序。当我编写路由到我的 REST 服务的 URL 时,我收到以下错误和浏览器中的空白页面。
这是堆栈跟踪:
15-May-2016 14:41:58.977 ERROR [http-nio-8080-exec-5] org.jboss.resteasy.core.ExceptionHandler.handleWebApplicationException RESTEASY002010: Failed to execute
javax.ws.rs.NotFoundException: RESTEASY003210: Could not find resource for full path: http://localhost:8080/api/v1/status
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:257)
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:194)
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:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:522)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1095)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:672)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1502)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1458)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
这是我的pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<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.taras.resty</groupId>
<artifactId>Resty</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxrs</artifactId>
<version>LATEST</version>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>LATEST</version>
</dependency>
</dependencies>
</project>
这是我的web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<servlet>
<servlet-name>V1_Status</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.taras.resty.status.V1_Status</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>V1_Status</servlet-name>
<url-pattern>/api/*</url-pattern>
</servlet-mapping>
</web-app>
这是处理我的 REST 请求的 class:
package com.taras.resty.status;
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.Application;
import javax.ws.rs.ApplicationPath;
@ApplicationPath("/v1/status")
public class V1_Status extends Application {
private static final String api_version= "00.01.00";
@GET
@Produces(MediaType.TEXT_HTML)
public String returnTitle(){
return "<p>Java Web Service</p>";
}
@Path("/version")
@GET
@Produces(MediaType.TEXT_HTML)
public String returnVersion(){
return "<p>Version + </p>" + api_version;
}
}
我使用的URL是:http://localhost:8080/api/v1/status
提前谢谢你。
编辑 - 已解决 对于将面临同样问题的人。 @tair 在解决我的错误方面帮助了我很多。试试他的版本(你可以在这里找到它 https://github.com/tsabirgaliev/hello-jaxrs)。 我们还没有找到原因,它不知何故消失了(魔法)。 当然,有关更详细的信息,请查看规范 http://docs.jboss.org/resteasy/docs/3.0.16.Final/userguide/html_single/index.html#d4e113
正如您的 web.xml 建议您使用的是 Servlets 3.1 兼容 Tomcat,Resteasy 的配置应该不同。请参考 Resteasy 官方文档 [1] 的 3.5. Standalone Resteasy in Servlet 3.0 Containers
部分。
如果您坚持旧式配置,您应该将 JAX-RS 应用程序指定为 init-param
for HttpServletDispatcher
:
<servlet>
<servlet-name>Resteasy</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.taras.resty.Application</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>V1_Status</servlet-name>
<url-pattern>/api/*</url-pattern>
</servlet-mapping>
<context-param>
<param-name>resteasy.servlet.mapping.prefix</param-name>
<param-value>/api</param-value>
</context-param>
无论哪种情况,您都必须继承 javax.ws.rs.Application
.
更新:这里 [2] 是一个完整的应用示例。使用 Tomcat 8.0.33
测试[1] http://docs.jboss.org/resteasy/docs/3.0.16.Final/userguide/html_single/index.html#d4e113