Endpoint Rest with Jersey does not display expected result

-1

I created a JavaEE project directly in Intellij and added the dependencies of JavaEE 8 via maven. The structure of the project is in this link .

web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
         version="4.0">
</web-app>

beans.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans
    xmlns="http://xmlns.jcp.org/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee 
                      http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
    bean-discovery-mode="all">
</beans>

JerseyConfig:

@ApplicationPath("resources")
public class JerseyConfig extends Application {

//    @Override
//    public Set<Class<?>> getClasses()
//    {
//        Set<Class<?>> yourResources = new HashSet<Class<?>>();
//        yourResources.add(MySimpleRest.class);
//        return yourResources;
//    }


}

MySimpleRest:

@Path("/info")
public class MySimpleRest {

    @GET
    public String get(){
        return "Hello Word";
    }
}

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<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>JavaEE</groupId>
    <artifactId>JavaEE</artifactId>
    <version>1.0-SNAPSHOT</version>
    <!--<packaging>war</packaging>-->

    <dependencies>
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-api</artifactId>
            <version>8.0</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>
</project>

I'm trying to access the url http://localhost:9090/resources/info and it returns me 404. What am I doing wrong?

    
asked by anonymous 10.10.2018 / 13:44

1 answer

1

I think the problem is in the startup class, I propose the following changes:

First add these (Jersey) dependencies to your pom.xml :

<dependency>
    <groupId>javax.ws.rs</groupId>
    <artifactId>javax.ws.rs-api</artifactId>
    <version>2.1</version>
</dependency>
<dependency>
    <groupId>org.glassfish.jersey.containers</groupId>
    <artifactId>jersey-container-servlet</artifactId>
    <version>2.27</version>
</dependency>
<!-- Isso é necessário se for usar a ultima versao do Jersey -->
<dependency>
    <groupId>org.glassfish.jersey.inject</groupId>
    <artifactId>jersey-hk2</artifactId>
    <version>2.26</version>
</dependency>

JerseyConfig:

@ApplicationPath("resources")
public class JerseyConfig extends ResourceConfig {

    public JerseyConfig() {
        //Scaneia Dinamicamente pelos Controllers (classes com @Path)
        packages("br.com.javaee.controllers");
    }
}

MySimpleRest:

@Path("/info")
public class MySimpleRest {

    @GET
    @Produces(MediaType.TEXT_PLAIN)
    public Response get() {
        return Response.ok("Hello Word").build();
    }
}

According to this link e

10.10.2018 / 13:53