Reputation: 13
It seems that any settings i try it doesn't work to access the methods in class. I keep getting 404 not found. This is the web.xml file:
<servlet>
<servlet-name>Restful Web Service</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>restfulexample.status</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Restful Web Service</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
and this the java file inside src/main/java:
package restfulexample.status;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
@Path("v1/status")
public class V1_status {
@GET
@Produces(MediaType.TEXT_PLAIN)
public String returnTitle(){
return "Java restful api";
}
}
Upvotes: 1
Views: 2403
Reputation: 93
If the route is right, I don't know if you put all of the .jar files of jersey(jersey2.x) in to the lib folder, because they are departed into three parts under jersey-ir/
Upvotes: 0
Reputation: 220
Could be me, but is @Path("v1/status")
not missing a slash? So basically @Path("/v1/status")
.
Just hit me: your url-pattern in web.xml is missing an asterisk. Change it to:
<servlet-mapping>
<servlet-name>Restful Web Service</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
Upvotes: 1