Error 404 apache Tomcat

Asked

Viewed 576 times

1

I am new to web services, however lately I have taken to develop mine, however I can’t even do a hello world due to an error that Tomcat is returning me, it just doesn’t find the URL, can help me?

package Login;

import javax.ws.rs.core.Context;
import javax.ws.rs.core.UriInfo;
import javax.ws.rs.Consumes;
import javax.ws.rs.Produces;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PUT;
import javax.ws.rs.core.MediaType;

/**
 * REST Web Service
 *
 * @author Matheus
 */
@Path("/Teste")
public class Teste {

    @Context
    private UriInfo context;

    /**
     * Creates a new instance of Teste
     */
    public Teste() {
    }

    /**
     * Retrieves representation of an instance of Login.Teste
     * @return an instance of java.lang.String
     */
    @GET
    @Produces("text/plain")
    public String getText() {
        //TODO return proper representation object
        return "ola";
    }

    /**
     * PUT method for updating or creating an instance of Teste
     * @param content representation for the resource
     */
    @PUT
    @Consumes(MediaType.TEXT_PLAIN)
    public void putText(String content) {
    }
}

The home URL is http://localhost:8080/Project, this page is easily found, however when I access the URL http://localhost:8080/Project/Test which is to return a "hello" it simply returns a 404 error from page not found.

inserir a descrição da imagem aqui

1 answer

1


You need to have a class that configures the application.

Put the following code:

package login;

import javax.ws.rs.core.Application;

@javax.ws.rs.ApplicationPath("api")
public class ApplicationConfig extends Application {}

With that it worked smoothly here at Glassfish.

The way to access the page will be:

http://localhost:8080/Projeto/api/Teste

Another important thing, package names should start with lower case letter, so I switched to login.

  • Buddy, do I need to create a class to put this code? Or is it just paste it into the class above?

  • You need to create a class in the login package with the name Applicationconfig and paste this code.

  • Buddy, I tried to make these changes here and keep returning code 404.

  • With me this alternative did not take effect @prmottajr

  • @Tiagoferezin what mistake happens there?

  • @prmottajr my intecept is shooting error

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.