简体   繁体   中英

RESTEASY003210: Could not find resource for full path : Tomcat

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-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

<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-jackson-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:

public class ScenarioPlannerApp  extends Application{}

I am using the following simple web service with URL http://localhost:9050/scenarioplanner/api/models/ :

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!!

Fixing the application path

Annotate the class that extends Application with @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:

@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 class designates a resource .

Creating resource methods

It's very likely you'll need to add more methods to the ModelController resource class. See the examples below:

To have a method that handles POST requests on /api/models , you can have the following:

@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
@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 method of a resource class designates a sub resource of a resource.

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")

That's it!!

Rest all was fine!

To those who are migrating their Resteasy version from 2.X to 3.X or 4.X.

The path matching algorithm has changed for JAX-RS 2.0 and became very strict.

In order for you to continue using your existing method's @Path , you must enable the resteasy.wider.request.matching Resteasy configuration.

web.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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM