Ho letto un numero di post, ma non riesco a risolvere il mio problema. Vedrai anche tonnellate di post molto simili a questo, anche lo stesso tutorial. Anche seguendo loro, non riesco a ottenere la risposta.Jersey REST Web Service, Tomcat, Eclipse e 404's
In sostanza, sto cercando di seguire il semplice tutorial all'indirizzo: http://www.vogella.com/articles/REST/
Ho fatto alcune modifiche per renderlo compatibile con Jersey 2.x
sto usando: Eclipse Tomcat 6 (Implementato/Esegui come all'interno di Eclipse) jaxrs-ri-2.0 ho permesso al JAX-RS Facet in Eclipse
Tutto costruisce bene Tomcat inizia bene all'interno di Eclipse posso arrivare a un contenuto di pagina statica tramite:
http://localhost:8080/RestTEST2/index.html
Tuttavia, quando provo ad accedere al mio servizio via:
http://localhost:8080/RestTEST2/jaxrs/hello
ricevo una 404 con "il messaggio non trovato" e "La risorsa richiesta (non trovata) non è disponibile."
Ecco il mio web.xml che è situato in /WebContent/WEB-INF/web.xml
<?xml version="1.0" encoding="UTF-8"?>
<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_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>TestREST2</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<servlet>
<description>JAX-RS Tools Generated - Do not modify</description>
<servlet-name>JAX-RS Servlet</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>TestREST</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>JAX-RS Servlet</servlet-name>
<url-pattern>/jaxrs/*</url-pattern>
</servlet-mapping>
</web-app>
ecco la mia classe Java:
package TestREST;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
// Plain old Java Object it does not extend as class or implements
// an interface
// The class registers its methods for the HTTP GET request using the @GET annotation.
// Using the @Produces annotation, it defines that it can deliver several MIME types,
// text, XML and HTML.
// The browser requests per default the HTML MIME type.
//Sets the path to base URL + /hello
@Path("/hello")
public class Hello {
// This method is called if TEXT_PLAIN is request
@GET
@Produces(MediaType.TEXT_PLAIN)
public String sayPlainTextHello() {
return "Hello Jersey";
}
// This method is called if XML is request
@GET
@Produces(MediaType.TEXT_XML)
public String sayXMLHello() {
return "<?xml version=\"1.0\"?>" + "<hello> Hello Jersey" + "</hello>";
}
// This method is called if HTML is request
@GET
@Produces(MediaType.TEXT_HTML)
public String sayHtmlHello() {
return "<html> " + "<title>" + "Hello Jersey" + "</title>"
+ "<body><h1>" + "Hello Jersey" + "</body></h1>" + "</html> ";
}
}
Ho anche un JAX- RS User Library configurato e referenziato che include tutti i jar JAX-RS.
Pensieri su cosa potrebbe causare il servizio Web non trovato?
impressionante. Ho combattuto per ore. Questo è stato risolto al mio problema. Ho anche avuto il mio nome del pacchetto errato in xml come testREST, quando avrebbe dovuto essere TestREST, ma questa era la radice del problema. Grazie mille. –
Dal tuo commento ho imparato a cambiare il pkg del provider sul mio pkg. Grazie –
Sto cercando di implementare lo stesso progetto ..... ma lo stesso errore persiste .. Ho provato tutte le soluzioni fornite qui e ho provato anche a cambiare la posizione del server tomcat .... – spt025