java RESTEASY003210:找不到完整路径的资源:Tomcat
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39857412/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
RESTEASY003210: Could not find resource for full path : Tomcat
提问by Sabyasachi
I am getting the following error:
我收到以下错误:
This is the stack trace:
这是堆栈跟踪:
javax.ws.rs.NotFoundException: RESTEASY003210: Could not find resource for full path: http://localhost:9050/scenarioplanner/api/models/
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:528)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1099)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:670)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1520)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1476)
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)
This is my web.xml
这是我的web.xml
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
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">
</webapp>
This is my pom.xml
这是我的pom.xml
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>us.deloitteinnovation.dmaanalytics.nissan.backend</groupId>
<artifactId>scenarioplanner</artifactId>
<packaging>war</packaging>
<version>1.0.0-SNAPSHOT</version>
<name>Scenario Planner Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-servlet-initializer</artifactId>
<version>3.0.12.Final</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.jboss.resteasy/resteasy-jaxb-provider -->
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxb-provider</artifactId>
<version>3.0.12.Final</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.jboss.resteasy/resteasy-jaxrs -->
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxrs</artifactId>
<version>3.0.12.Final</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.jboss.resteasy/resteasy-validator-provider-11 -->
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-validator-provider-11</artifactId>
<version>3.0.12.Final</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-Hymanson-provider</artifactId>
<version>3.0.12.Final</version>
</dependency>
<dependency>
<groupId>net.sf.scannotation</groupId>
<artifactId>scannotation</artifactId>
<version>1.0.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.ws.rs/javax.ws.rs-api -->
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.1-m01</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.jasypt/jasypt -->
<dependency>
<groupId>org.jasypt</groupId>
<artifactId>jasypt</artifactId>
<version>1.9.2</version>
</dependency>
</dependencies>
<build>
<finalName>scenarioplanner</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
I have declared an empty Application class here:
我在这里声明了一个空的 Application 类:
public class ScenarioPlannerApp extends Application{}
I am using the following simple web service with URL http://localhost:9050/scenarioplanner/api/models/:
我正在使用以下带有 URL http://localhost:9050/scenarioplanner/api/models/ 的简单 Web 服务:
The Resource Code is :
资源代码是:
@Path("")
public class ModelController
{
@GET
@Path("/models/")
@Produces(MediaType.APPLICATION_JSON)
public Response getModels() throws Exception {
ModelService modelService = null;
List<CarModelData> models;
models = modelService.getModelDetails();
logger.debug("Webservice Name [/models/] execution completed with HTTP status OK [200]");
//return Responsestatus(Status.OK).entity(models).build();
return Response
.status(Status.OK)
.entity(models)
.build();
}
I have read many answers on stack overflow, but not able to solve this error. I have spent the whole day trying to debug this error but in vain!
我已经阅读了许多有关堆栈溢出的答案,但无法解决此错误。我花了一整天试图调试这个错误,但徒劳无功!
Any help will be highly valued and appreciated!!
任何帮助都将受到高度重视和赞赏!!
采纳答案by cassiomolin
Fixing the application path
修复应用程序路径
Annotate the class that extends Application
with @ApplicationPath
:
注释扩展类Application
有@ApplicationPath
:
@ApplicationPath("/api")
public class ScenarioPlannerApp extends Application {
...
}
Fixing the resource path
修复资源路径
Annotate the ModelController
class with @Path
using /models
as value. The getModels()
method doesn't need a @Path
annotation in this situation:
使用作为值来注释ModelController
类。在这种情况下,该方法不需要注释:@Path
/models
getModels()
@Path
@Path("/models")
public class ModelController {
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getModels() throws Exception {
...
}
}
It's important to remember that a @Path
annotation on a resource classdesignates a resource.
重要的是要记住,资源类@Path
上的注释指定了一个资源。
Creating resource methods
创建资源方法
It's very likely you'll need to add more methods to the ModelController
resource class. See the examples below:
您很可能需要向ModelController
资源类添加更多方法。请参阅以下示例:
To have a method that handles POST
requests on /api/models
, you can have the following:
要使用处理POST
请求的方法/api/models
,您可以使用以下方法:
@POST
@Consumes(MediaType.APPLICATION_JSON)
public Response createModel(Model model) throws Exception {
...
}
To have a method that handles GET
requests on /api/models/{id}
, you can have the following:
要使用处理GET
请求的方法/api/models/{id}
,您可以使用以下方法:
@GET
@Path("/{id}")
@Produces(MediaType.APPLICATION_JSON)
public Response getModel(@PathParam("id") Long id) throws Exception {
...
}
And it's important to remember that a @Path
annotation on a resource methodof a resource class designates a sub resourceof a resource.
重要的是要记住,资源类@Path
的资源方法上的注释指定了资源的子资源。
回答by Sabyasachi
This issue has been solved by me. This is what I needed to do:
这个问题已经被我解决了。这是我需要做的:
@Path("")
public class ModelController
{
@GET
@Path("/models/")
@Produces(MediaType.APPLICATION_JSON)
public Response getModels() throws Exception {
return Response
.status(Status.OK)
.entity(models)
.build();
}
In the above piece of code,
在上面的一段代码中,
I had to change the path @Path("") to @Path("/api")
我不得不 change the path @Path("") to @Path("/api")
That's it!!
而已!!
Rest all was fine!
休息一切都很好!
回答by Melvin Sy
To those who are migrating their Resteasy version from 2.X to 3.X or 4.X.
对于那些将他们的 Resteasy 版本从 2.X 迁移到 3.X 或 4.X 的人。
The path matching algorithm has changed for JAX-RS 2.0 and became very strict.
JAX-RS 2.0 的路径匹配算法已经改变并且变得非常严格。
In order for you to continue using your existing method's @Path
, you must enable the resteasy.wider.request.matching
Resteasy configuration.
为了让您继续使用现有方法的@Path
,您必须启用resteasy.wider.request.matching
Resteasy 配置。
web.xml
网页.xml
<context-param>
<param-name>resteasy.wider.request.matching</param-name>
<param-value>true</param-value>
</context-param>
Reference: Resteasy Migration Guide Section 55.3