如何配置HATEOAS Jax-Rs Link.fromUri

时间:2019-06-16 09:26:06

标签: jax-rs hateoas

我正在使用JAX-RS,并且希望将HATEOAS链接添加到响应中。这是一个行家项目。对GET方法执行请求时出现错误。我在服务器控制台中看到错误

依赖项是

enter image description here

说明是

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

当我执行请求时,我进入控制台服务器错误

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:198)

这本书的课是

package com.readlearncode.dukesbookshop.restserver.domain;


import java.io.Serializable;
import java.util.Date;
import java.util.List;

import com.readlearncode.dukesbookshop.restserver.domain.Author; 

import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement
public class Book  extends Hypermedia implements Serializable{

    private String id;
    private String title;
    private String description;
    private List<Author> authors;
    private Float price;
    private String imageFileName;
    private String link;
    private Date published;

    public Book() {

    }
    public Book(String id, String title, String description,List<Author> authors, Float price, String imageFileName, String link,
            Date published) {
        super();
        this.id = id;
        this.title = title;
        this.description = description;
        this.authors = authors;
        this.price = price;
        this.imageFileName = imageFileName;
        this.link = link;
        this.published = published;
    }

超媒体类

package com.readlearncode.dukesbookshop.restserver.domain;

import java.util.ArrayList;
import java.util.List;

import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement
public class Hypermedia {

    private List<LinkResource> links = new ArrayList<LinkResource>();


    public void addLink(LinkResource linkResource ) {
        this.links.add(linkResource);
    }

    public List<LinkResource> getLinks() {
        return links;
    }

    public void setLinks(List<LinkResource> links) {
        this.links = links;
    }



}

我如何配置HATEOAS链接?

0 个答案:

没有答案