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

前端 未结 7 2161
长情又很酷
长情又很酷 2020-12-06 01:59

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 wildfl

7条回答
  •  借酒劲吻你
    2020-12-06 02:32

    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.0
    
        com.easyrest
        easyrest
        1.0-SNAPSHOT
        war
    
        easyrest
    
        
            ${project.build.directory}/endorsed
            UTF-8
        
    
        
        
            
                org.jboss.resteasy
                http://repo.maven.apache.org/maven2/
            
        
    
        
            
                org.jboss.resteasy
                resteasy-jaxrs
                3.0.10.Final
            
            
                org.jboss.resteasy
                resteasy-servlet-initializer
                3.0.10.Final
            
            
                javax
                javaee-web-api
                6.0
                provided
            
        
    
        
            
                
                    org.apache.maven.plugins
                    maven-compiler-plugin
                    2.3.2
                    
                        1.6
                        1.6
                        
                            ${endorsed.dir}
                        
                    
                
                
                    org.apache.maven.plugins
                    maven-war-plugin
                    2.3
                    
                        false
                    
                
                
                    org.apache.maven.plugins
                    maven-dependency-plugin
                    2.1
                    
                        
                            validate
                            
                                copy
                            
                            
                                ${endorsed.dir}
                                true
                                
                                    
                                        javax
                                        javaee-endorsed-api
                                        6.0
                                        jar
                                    
                                
                            
                        
                    
                
            
        
    
    
    

提交回复
热议问题