TomEE JAX-RS java.lang.NoSuchMethodError javax.ws.rs.core.Link.fromUri - PullRequest
0 голосов
/ 15 июня 2019

У меня есть проект Maven, и я работаю с сервером TomEE.У меня есть служба JAX-RS.Я хочу добавить ссылки HATEOAS к Ответу и использую класс Link.

Мой 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>

    <parent>
        <groupId>com.readlearncode</groupId>
        <artifactId>dukesbookshop</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>

    <artifactId>rest-server</artifactId>
    <packaging>war</packaging>

    <name>rest-server</name>
    <url>http://localhost:8080</url>

    <properties>
        <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
        <java.version>1.8</java.version>
        <javaee-api.version>7.0</javaee-api.version>
    </properties>

    <dependencies>

        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-api</artifactId>
            <version>${javaee-api.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.openejb</groupId>
             <artifactId>javaee-api</artifactId>
              <version>6.0-6</version>
             <scope>provided</scope>
        </dependency>

        <!-- https://mvnrepository.com/artifact/javax.ws.rs/javax.ws.rs-api -->
         <dependency>
              <groupId>javax.ws.rs</groupId>
              <artifactId>javax.ws.rs-api</artifactId>
            <version>2.0.1</version>
        </dependency>

    </dependencies>

    <build>
        <finalName>rest-server</finalName>
        <plugins>

            <plugin>
                  <groupId>org.apache.openejb.maven</groupId>
                 <artifactId>tomee-maven-plugin</artifactId>
                 <version>1.7.1</version>
                <configuration>
                     <tomeeVersion>1.7.1</tomeeVersion>
                     <tomeeClassifier>plus</tomeeClassifier>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.6.0</version>
                <configuration>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                    <compilerArguments>
                        <endorseddirs>${endorsed.dir}</endorseddirs>
                    </compilerArguments>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>3.0.0</version>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                    <filteringDeploymentDescriptors>true</filteringDeploymentDescriptors>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.18.1</version>
                <configuration>
                    <skipTests>true</skipTests>
                    <systemPropertyVariables>
                        <!-- This is needed to tell the unit tests which profile we are running. -->
                    </systemPropertyVariables>
                </configuration>
            </plugin>
        </plugins>
    </build>


</project>

Мое приложение запускается сразу, когда я запускаю сервер, но когда я проверяюс почтальоном URL

http://localhost:8080/rest-server/api/books/2526987585

Я вижу в консоли сервера ошибку

Caused by: java.lang.NoSuchMethodError: javax.ws.rs.ext.RuntimeDelegate.createLinkBuilder()Ljavax/ws/rs/core/Link$Builder;
    at javax.ws.rs.core.Link.fromUri(Link.java:185)

Инструкция в сервисе:

Link self = Link.fromUri(uriInfo.getBaseUriBuilder()
                    .path(getClass())
                    .path(getClass(), "getBookByIsbn")
                    .build(book.get().getId()))
                    .rel("self")
                    .type("GET")
                    .build();

Как мне настроить ссылки HATEOAS в ответе?

...