Конечная точка сервиса JavaEE 7 RESTfull не работает - PullRequest
0 голосов
/ 06 апреля 2020

Я создал проект с веб-модулем, используя maven. Структура проекта:

enter image description here

Простой java Класс:


public class Student {

    private String firstName;
    private String lastName;

    public Student(String firstName, String lastName) {
        this.firstName = firstName;
        this.lastName = lastName;
    }

    public String getFirstName() {
        return firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }
}

и услуга:

import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.util.ArrayList;
import java.util.List;

@Path("students")
public class StudentService {

    @GET
    @Path("all")
    @Produces(MediaType.APPLICATION_JSON)
    public List<Student> getStudentList(){
            List<Student> students = initailStudentList();
            return students;
    }

    public List<Student> initailStudentList(){
        List<Student> students = new ArrayList<>();

        Student student1 = new Student("Jan","Kowalski");
        Student student2 = new Student("Anna","Nowak");

        students.add(student1);
        students.add(student2);

        return students;
    }

}

добавил в pom зависимости resreasy. 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/maven-v4_0_0.xsd">
    <name>lab-rest</name>
    <modelVersion>4.0.0</modelVersion>
    <groupId>pl.edu.agh.soa.rest</groupId>
    <artifactId>lab-rest</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>pom</packaging>

    <url>http://wildfly.org</url>
    <licenses>
        <license>
            <name>Apache License, Version 2.0</name>
            <distribution>repo</distribution>
            <url>http://www.apache.org/licenses/LICENSE-2.0.html</url>
        </license>
    </licenses>
    <modules>
        <module>lab-rest-ejb</module>
        <module>lab-rest-web</module>
        <module>lab-rest-ear</module>
    </modules>

    <properties>
        <!-- Explicitly declaring the source encoding eliminates the following 
            message: -->
        <!-- [WARNING] Using platform encoding (UTF-8 actually) to copy filtered 
            resources, i.e. build is platform dependent! -->
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

        <!-- JBoss dependency versions -->

        <version.wildfly.maven.plugin>1.0.2.Final</version.wildfly.maven.plugin>

        <!-- Define the version of the JBoss BOMs we want to import to specify tested stacks. -->
        <version.jboss.bom>8.2.1.Final</version.jboss.bom>
        <version.wildfly>9.0.0.Alpha1</version.wildfly>


        <!-- other plugin versions -->
        <version.compiler.plugin>3.1</version.compiler.plugin>
        <version.ear.plugin>2.10</version.ear.plugin>
        <version.ejb.plugin>2.3</version.ejb.plugin>
        <version.surefire.plugin>2.16</version.surefire.plugin>
        <version.war.plugin>2.5</version.war.plugin>

        <!-- maven-compiler-plugin -->
        <maven.compiler.target>1.7</maven.compiler.target>
        <maven.compiler.source>1.7</maven.compiler.source>
    </properties>

    <dependencyManagement>
        <dependencies>

            <!-- Define the version of the EJB jar so that we don't need 
                to repeat ourselves in every module -->
            <dependency>
                <groupId>pl.edu.agh.soa.rest</groupId>
                <artifactId>lab-rest-ejb</artifactId>
                <version>${project.version}</version>
                <type>ejb</type>
            </dependency>

            <!-- Define the version of the WAR so that we don't need to repeat 
                ourselves in every module -->
            <dependency>
                <groupId>pl.edu.agh.soa.rest</groupId>
                <artifactId>lab-rest-web</artifactId>
                <version>${project.version}</version>
                <type>war</type>
                <scope>compile</scope>
            </dependency>

            <dependency>
                <groupId>org.wildfly.bom</groupId>
                <artifactId>jboss-javaee-7.0-with-tools</artifactId>
                <version>${version.jboss.bom}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>

            <dependency>
                <groupId>org.wildfly.bom</groupId>
                <artifactId>jboss-javaee-7.0-with-hibernate</artifactId>
                <version>${version.jboss.bom}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>

            <!-- https://mvnrepository.com/artifact/org.jboss.logging/jboss-logging -->
            <dependency>
                <groupId>org.jboss.logging</groupId>
                <artifactId>jboss-logging</artifactId>
                <version>3.4.1.Final</version>
            </dependency>

            <!-- https://mvnrepository.com/artifact/org.jboss.spec.javax.annotation/jboss-annotations-api_1.2_spec -->
            <dependency>
                <groupId>org.jboss.spec.javax.annotation</groupId>
                <artifactId>jboss-annotations-api_1.2_spec</artifactId>
                <version>1.0.2.Final</version>
            </dependency>

            <!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->
            <dependency>
                <groupId>javax.servlet</groupId>
                <artifactId>javax.servlet-api</artifactId>
                <version>4.0.1</version>
                <scope>provided</scope>
            </dependency>

            <!-- https://mvnrepository.com/artifact/org.jboss.resteasy/resteasy-jaxrs -->
            <dependency>
                <groupId>org.jboss.resteasy</groupId>
                <artifactId>resteasy-jaxrs</artifactId>
                <version>4.0.0.Beta5</version>
            </dependency>

            <!-- https://mvnrepository.com/artifact/org.jboss.resteasy/resteasy-jackson2-provider -->
            <dependency>
                <groupId>org.jboss.resteasy</groupId>
                <artifactId>resteasy-jackson2-provider</artifactId>
                <version>4.5.3.Final</version>
            </dependency>

            <!-- https://mvnrepository.com/artifact/org.jboss.resteasy/resteasy-jaxb-provider -->
            <dependency>
                <groupId>org.jboss.resteasy</groupId>
                <artifactId>resteasy-jaxb-provider</artifactId>
                <version>4.5.3.Final</version>
            </dependency>

            <!-- https://mvnrepository.com/artifact/org.jboss.resteasy/resteasy-multipart-provider -->
            <dependency>
                <groupId>org.jboss.resteasy</groupId>
                <artifactId>resteasy-multipart-provider</artifactId>
                <version>4.5.3.Final</version>
            </dependency>

            <!-- https://mvnrepository.com/artifact/org.jboss.resteasy/resteasy-client -->
            <dependency>
                <groupId>org.jboss.resteasy</groupId>
                <artifactId>resteasy-client</artifactId>
                <version>4.5.3.Final</version>
            </dependency>

            <!-- https://mvnrepository.com/artifact/org.jboss.resteasy/jaxrs-api -->
            <dependency>
                <groupId>org.jboss.resteasy</groupId>
                <artifactId>jaxrs-api</artifactId>
                <version>3.0.12.Final</version>
            </dependency>

            <!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
            <dependency>
                <groupId>commons-io</groupId>
                <artifactId>commons-io</artifactId>
                <version>2.6</version>
            </dependency>



        </dependencies>
    </dependencyManagement>

    <build>
        <pluginManagement>
            <plugins>
                <!-- The WildFly plugin deploys your ear to a local JBoss
                    AS container -->
                <!-- Due to Maven's lack of intelligence with EARs we need 
                    to configure the wildfly maven plugin to skip deployment for all modules.
                    We then enable it specifically in the ear module. -->
                <plugin>
                    <groupId>org.wildfly.plugins</groupId>
                    <artifactId>wildfly-maven-plugin</artifactId>
                    <version>${version.wildfly.maven.plugin}</version>
                    <inherited>true</inherited>
                    <configuration>
                        <skip>true</skip>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>

</project>

Развертывание на WildFly прошло успешно, но при попытке ввести: http://localhost: 8080 / lab-rest-web / Students / все

Я получаю

Не найдено

Я немного запутался в сети. xml отсутствует, но я не знать, как его генерировать ..

...