javax.ws.rs.NotFoundException: Could not find resource for full path with RESTEasy and Wildfly 8.1.0.Final

匿名 (未验证) 提交于 2019-12-03 01:18:02

问题:

I am facing following problem. I have spent more than 3 days on this but cannot find a solution. Please guide me what I am doing wrong here. I am new to Resteasy with wildfly.

Here is the stacktrace

19:05:57,610 WARN  [org.jboss.resteasy.core.ExceptionHandler] (default task-14) failed to execute: javax.ws.rs.NotFoundException: Could not find resource for full path: http://localhost:8080/admin-ws/services/user/getUser     at org.jboss.resteasy.core.registry.ClassNode.match(ClassNode.java:73) [resteasy-jaxrs-3.0.8.Final.jar:]     at org.jboss.resteasy.core.registry.RootClassNode.match(RootClassNode.java:48) [resteasy-jaxrs-3.0.8.Final.jar:]     at org.jboss.resteasy.core.ResourceMethodRegistry.getResourceInvoker(ResourceMethodRegistry.java:444) [resteasy-jaxrs-3.0.8.Final.jar:]     at org.jboss.resteasy.core.SynchronousDispatcher.getInvoker(SynchronousDispatcher.java:234) [resteasy-jaxrs-3.0.8.Final.jar:]     at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:171) [resteasy-jaxrs-3.0.8.Final.jar:]     at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:220) [resteasy-jaxrs-3.0.8.Final.jar:]     at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56) [resteasy-jaxrs-3.0.8.Final.jar:]     at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51) [resteasy-jaxrs-3.0.8.Final.jar:]     at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) [jboss-servlet-api_3.1_spec-1.0.0.Final.jar:1.0.0.Final]     at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]     at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:61) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]     at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]     at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)     at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.15.Final.jar:1.0.15.Final]     at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:113) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]     at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:56) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]     at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.15.Final.jar:1.0.15.Final]     at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:45) [undertow-core-1.0.15.Final.jar:1.0.15.Final]     at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:61) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]     at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:58) [undertow-core-1.0.15.Final.jar:1.0.15.Final]     at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:70) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]     at io.undertow.security.handlers.SecurityInitialHandler.handleRequest(SecurityInitialHandler.java:76) [undertow-core-1.0.15.Final.jar:1.0.15.Final]     at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.15.Final.jar:1.0.15.Final]     at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)     at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.15.Final.jar:1.0.15.Final]     at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.15.Final.jar:1.0.15.Final]     at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:240) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]     at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:227) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]     at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:73) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]     at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:146) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]     at io.undertow.server.Connectors.executeRootHandler(Connectors.java:177) [undertow-core-1.0.15.Final.jar:1.0.15.Final]     at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:727) [undertow-core-1.0.15.Final.jar:1.0.15.Final]     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [rt.jar:1.8.0_20]     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [rt.jar:1.8.0_20]     at java.lang.Thread.run(Thread.java:745) [rt.jar:1.8.0_20] 

Here is my web.xml

Here is the Application class.

package com.abc.admin.services.config;  import javax.ws.rs.ApplicationPath; import javax.ws.rs.core.Application;  @ApplicationPath("/services") public class WebConfig extends Application {  } 

Here is the web service class.

package com.abc.admin.service;  import java.io.Serializable;  import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType;  import com.abc.commons.ws.entity.UserWsPojo;  @Path("/user") public class UserResource implements Serializable {      private static final long serialVersionUID = 6766329501327292893L;      @GET     @Path("/services/user/getUser")     @Produces(MediaType.APPLICATION_JSON)     public UserWsPojo getUser(String id) {         UserWsPojo uwp = new UserWsPojo();         uwp.setName("Aayush");         uwp.setSurname("Devmurari");         return uwp;     } } 

Now in the above mentioned class I also tried to change the path of @Path with /getUser and also tried full path i.e. @Path("/services/user/getUser") none of these are working everytime I get the same error.

If you need to see anything else please let me know. I will post it here.

Thanks for reading and helping.

P.S I have tried reading other questions on SO, documentation on RestEasy none of this helped me much. However I corrected my code while looking for the solution.

Based on the answers I did this too

@Path("/user") public class UserResource implements Serializable {      private static final long serialVersionUID = 6766329501327292893L;      @GET     @Path("/getUser")     @Produces(MediaType.APPLICATION_JSON)     public UserWsPojo getUser() {         UserWsPojo uwp = new UserWsPojo();         uwp.setName("Aayush");         uwp.setSurname("Devmurari");         return uwp;     } } 

Other things are same as they are, still I am getting the same error.

22:15:58,489 WARN  [org.jboss.resteasy.core.ExceptionHandler] (default task-5) failed to execute: javax.ws.rs.NotFoundException: Could not find resource for full path: http://localhost:8080/admin-ws/services/user/getUsers     at org.jboss.resteasy.core.registry.ClassNode.match(ClassNode.java:73) [resteasy-jaxrs-3.0.8.Final.jar:]     at org.jboss.resteasy.core.registry.RootClassNode.match(RootClassNode.java:48) [resteasy-jaxrs-3.0.8.Final.jar:]     at org.jboss.resteasy.core.ResourceMethodRegistry.getResourceInvoker(ResourceMethodRegistry.java:444) [resteasy-jaxrs-3.0.8.Final.jar:]     at org.jboss.resteasy.core.SynchronousDispatcher.getInvoker(SynchronousDispatcher.java:234) [resteasy-jaxrs-3.0.8.Final.jar:]     at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:171) [resteasy-jaxrs-3.0.8.Final.jar:]     at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:220) [resteasy-jaxrs-3.0.8.Final.jar:]     at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56) [resteasy-jaxrs-3.0.8.Final.jar:]     at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51) [resteasy-jaxrs-3.0.8.Final.jar:]     at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) [jboss-servlet-api_3.1_spec-1.0.0.Final.jar:1.0.0.Final]     at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]     at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:61) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]     at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]     at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)     at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.15.Final.jar:1.0.15.Final]     at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:113) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]     at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:56) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]     at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.15.Final.jar:1.0.15.Final]     at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:45) [undertow-core-1.0.15.Final.jar:1.0.15.Final]     at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:61) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]     at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:58) [undertow-core-1.0.15.Final.jar:1.0.15.Final]     at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:70) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]     at io.undertow.security.handlers.SecurityInitialHandler.handleRequest(SecurityInitialHandler.java:76) [undertow-core-1.0.15.Final.jar:1.0.15.Final]     at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.15.Final.jar:1.0.15.Final]     at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)     at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.15.Final.jar:1.0.15.Final]     at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.15.Final.jar:1.0.15.Final]     at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:240) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]     at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:227) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]     at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:73) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]     at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:146) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]     at io.undertow.server.Connectors.executeRootHandler(Connectors.java:177) [undertow-core-1.0.15.Final.jar:1.0.15.Final]     at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:727) [undertow-core-1.0.15.Final.jar:1.0.15.Final]     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [rt.jar:1.8.0_20]     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [rt.jar:1.8.0_20]     at java.lang.Thread.run(Thread.java:745) [rt.jar:1.8.0_20] 

回答1:

  • Base:

    (1) http://localhost:8080/admin-ws  (I assume `admin-ws` is the app name) 
  • @ApplicationPath("/services") == append /services to Base

    (2) http://localhost:8080/admin-ws/services 
  • @Path("/user") == append /user to previous

    (3) http://localhost:8080/admin-ws/services/user 
  • @Path("/services/user/getUser") == append /services/user/getUser to previous

    (4) http://localhost:8080/admin-ws/services/user/services/user/getUser            //This is the winner with your current set up 
  • What you are using:

    http://localhost:8080/admin-ws/services/user/getUser 

    What's different?

How it Should Look : to follow good REST (naming included) practices

@ApplicationPath("/services") public class WebConfig extends Application { }  @Path("/users") public class UserResource implements Serializable {      @Inject     private UserService userService;      @GET     @Path("/{id}")     @Produces(MediaType.APPLICATION_JSON)     public UserWsPojo getUser(@PathParam("id") String id) {         UserWsPojo uwp = userService.getUserById(id);         return uwp;     } } 

Access:

http://localhost:8080/admin-ws/services/users/12344                                        // some user id 


回答2:

I got the same issue when I tried with 3.0.11.Final

org.jboss.resteasyresteasy-jaxrs3.0.11.Final

but when I tried with another version it worked.

org.jboss.resteasyresteasy-jaxrs3.0.4.Final

Hope this helps.



回答3:

Consolidating all the response and below code should work. Tested in tomcat 7.0.56, RESTEasy 3.0.10, Netbeans 8.0.2

WebConfig.java:

import javax.ws.rs.ApplicationPath; import javax.ws.rs.core.Application; @ApplicationPath("/services") public class WebConfig extends Application {  // No methods defined inside } 

SayHello.java:

import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.core.Response; import javax.ws.rs.Produces; @Path("/greet") public class SayHello {  @GET     @Path("/{username}")     @Produces("text/html")     public Response printMessage(@PathParam("username") String username) {         return Response.status(200).entity("Hello " + username).build();     }  } 

Netbeans generated web.xml: no change needed

             30         

URL to Your REST SERVICE:

http://hostname://services/greet/

Expected Response:

Hello 

Netbeans generated POM.XML: (make sure to include resteasy-servlet-initializer dependency if using tomcat and version 2.3 or greater for maven-war-plugin)

4.0.0com.easyresteasyrest1.0-SNAPSHOTwareasyrest${project.build.directory}/endorsedUTF-8org.jboss.resteasyhttp://repo.maven.apache.org/maven2/org.jboss.resteasyresteasy-jaxrs3.0.10.Finalorg.jboss.resteasyresteasy-servlet-initializer3.0.10.Finaljavaxjavaee-web-api6.0providedorg.apache.maven.pluginsmaven-compiler-plugin2.3.21.61.6${endorsed.dir}org.apache.maven.pluginsmaven-war-plugin2.3falseorg.apache.maven.pluginsmaven-dependency-plugin2.1validatecopy${endorsed.dir}truejavaxjavaee-endorsed-api6.0jar


回答4:

I faced the same problem (javax.ws.rs.NotFoundException: Could not find resource for full path ...). Based on this link, the steps to solve the issue are below:

1) Set the application class:

/**  * Application class  */ package com.abc.admin.services.config;  import javax.ws.rs.ApplicationPath; import javax.ws.rs.core.Application;  @ApplicationPath("/services") // the begining of the Webservice URL public class WebConfig extends Application {     private Set singletons = new HashSet();      public WebConfig() {         singletons.add(new UserResource());     }      @Override     public Set getSingletons() {         return singletons;     } } 


2) Set the Resource class:

/**  * Resource class  */ package com.abc.admin.service;  import java.io.Serializable; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType;  import com.abc.commons.ws.entity.UserWsPojo;  @Path("/user") public class UserResource implements Serializable {      private static final long serialVersionUID = 6766329501327292893L;      @GET     // there is a URL concatenation to access the method (.../services/user/getUser)     @Path("/getUser")      @Produces(MediaType.APPLICATION_JSON)     public UserWsPojo getUser(String id) {         UserWsPojo uwp = new UserWsPojo();         uwp.setName("Aayush");         uwp.setSurname("Devmurari");         return uwp;     } } 


3) Set the web.xml:

restContextindex.htmlresteasy.servlet.mapping.prefix/restresteasy-servlet         org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher     javax.ws.rs.Applicationcom.abc.admin.services.config.WebConfigresteasy-servlet/rest/*


4) Test the configuration in a browser:

http://localhost:8080/restContext/rest/services/user/getUser



回答5:

This works for all my services.

This is a runtime exception indicating a resource requested by a client was not found on the server. Add below entry into your web.xml :  resteasy.resourcescom.org.abc.xyz.MainClassName

You can specify fully qualified name of your JAX-RS resource class name you want to register. If you have multiple classes entries, use comma delimiter.



回答6:

Its hard to say for sure, but one thing I see is that you are passing a parameter but not mapping any parameter in the URL. This would be more correct:

@GET @Path("/getUser/{id}") @Produces(MediaType.APPLICATION_JSON) public UserWsPojo getUser(@PathParam("id") String id) {   // do things with stuff } 

And then the full URL would be /admin-ws/services/user/getUser/1 to get a user with ID 1.



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!