Je commence avec restapi et j'ai pensé à le faire avec un programme de base trouvé sur internet. Vous partager le code.Erreur HTTP 404 lors de la création de l'API REST sur Java
Le fichier de classe:
package com.java2novice.restful;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.Response;
@Path("/publish")
public class RestEasyExample {
@GET
@Path("/{message}")
public Response publishMessage(@PathParam("message") String msgStr){
String responseStr = "Received message: "+msgStr;
return Response.status(200).entity(responseStr).build();
}
}
Le web.xml-
<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<!-- Auto scan REST service -->
<context-param>
<param-name>resteasy.scan</param-name>
<param-value>true</param-value>
</context-param>
<servlet>
<servlet-name>resteasy-servlet</servlet-name>
<servlet-class>
org.glassfish.jersey.servlet.ServletContainer
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>resteasy-servlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
Le 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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>RestfulWebServices</groupId>
<artifactId>RestfulWebServices</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
</project>
J'utilise le maillot 2.0. J'ai déployé la guerre et l'ai placé dans le dossier webapps de Tomcat. Je l'ai essayé d'appeler à l'aide de deux urls-
http://localhost:8080/RestfulWebServices/publish/abc
et
http://localhost:8080/RestfulWebServices/publish?message=abc
Mais je ne bouge pas sur l'obtention HTTP 404 introuvable.
S'il vous plaît aidez-moi où il me manque quelque chose.
Merci