标签: spring-hateoas

找不到HATEOAS方法

我的控制器似乎无法找到像"linkTo"这样的HATEOAS方法.

我错过了什么吗?

的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>org.springframework</groupId>
    <artifactId>provider</artifactId>
    <version>0.1.0</version>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.1.5.RELEASE</version>
    </parent>

    <dependencies>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <!-- Spring Security -->
        <!-- Auto configured, remove dependencies to disable. -->
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-config</artifactId>
        </dependency>

        <!-- OAuth 2.0 -->
        <dependency>
            <groupId>org.springframework.security.oauth</groupId>
            <artifactId>spring-security-oauth2</artifactId>
            <version>2.0.1.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test-mvc</artifactId>
            <version>1.0.0.M2</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
        </dependency>

        <!-- Spring MongoDB -->
        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-mongodb</artifactId>
        </dependency>

        <!-- Spring REST MVC …
Run Code Online (Sandbox Code Playgroud)

spring-hateoas spring-boot

1
推荐指数
5
解决办法
4223
查看次数

如何使用spring boot和spring hateoas格式化json Date格式

我正在开发弹簧靴和春天的hateoas来创建一个休息api.
我需要将日期格式格式化为"yyyy-MM-dd".

我不想使用@JsonFormat,因为这个注释必须在我们使用Date的任何地方使用.

所以请帮助我在全球范围内实现这种配置,而不是在任何地方使用@JsonFormat.

spring-hateoas spring-boot

1
推荐指数
1
解决办法
1733
查看次数

如何在Spring Hateos中为ResourceAssembler编写mockito测试用例?

我正在尝试为下面的汇编程序编写单元测试,但我一直在通过RequestContextHolder找不到当前请求.这是从Spring MVC处理程序调用的吗?.我想知道如何模拟资源创建?

@Component
    public class LoginResourceAssembler extends ResourceAssemblerSupport<User, ResourceSupport> {

        public LoginResourceAssembler() {

            super(User.class, ResourceSupport.class);
        }

        @Override
        public ResourceSupport toResource(User user) {

            ResourceSupport resource = new ResourceSupport();
            final String id = user.getId();

            resource.add(linkTo(MyAccountsController.class).slash(id).slash("accounts").withRel("accounts"));

            return resource;
        }

    }
Run Code Online (Sandbox Code Playgroud)

spring-mvc mockito spring-hateoas

1
推荐指数
1
解决办法
1250
查看次数

Spring Boot Zuul hatoas REST 响应在资源中有直接服务链接

我有 Zuul + Eureka + Spring Boot Service Endpoint + Hateoas 响应配置。当我通过 Zuul Gateway 访问服务时,响应中的资源链接是到服务端点的直接链接,它们不应该是网关链接吗?我在这里缺少什么?

网关端点:http://localhost:8762/catalog/products/10001 直接服务端点:http://localhost:8100/products/10001

Zuul 的 application.properties

spring.application.name=zuul-server
eureka.client.service-url.default-zone=http://localhost:8761/eureka/

# Map paths to services
zuul.routes.catalog-service=/catalog/**
zuul.addProxyHeaders=true
Run Code Online (Sandbox Code Playgroud)

网关端点的实际响应:http://localhost:8762/catalog/products/10001

{
  "title" : "The Title",
  "description" : "The Description",
  "brand" : "SOME BRAND",
  "price" : 100,
  "color" : "Black",
  "_links" : {
    "self" : {
      "href" : "http://localhost:8100/products/10001"
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

预期响应应在 href 中包含网关 URL

{
  "title" : "The Title",
  "description" : "The Description",
  "brand" : "SOME …
Run Code Online (Sandbox Code Playgroud)

spring spring-hateoas spring-boot netflix-eureka netflix-zuul

1
推荐指数
1
解决办法
420
查看次数

将 Spring hatos ResourceAssembler 迁移到 RepresentationModelAssembler

根据这篇文章 ResourceAssembler改为RepresentationModelAssembler

我有这个使用 Spring HATEOAS 1.0 的代码:

import org.springframework.hateoas.ResourceAssembler;

public class BaseAssembler<T extends BaseTransaction, D extends BaseResource>
        implements ResourceAssembler<T, D> {
        ...
}
Run Code Online (Sandbox Code Playgroud)

迁移到后implementation 'org.springframework.boot:spring-boot-starter-hateoas:2.6.4' 我将其更改为:

public class BaseAssembler<T extends BaseTransaction, D extends BaseResource>
        implements RepresentationModelAssembler<T, D> {
        .........
}
Run Code Online (Sandbox Code Playgroud)

但我收到错误:

Type parameter 'D' is not within its bound; should extend 'org.springframework.hateoas.RepresentationModel<?>'
Run Code Online (Sandbox Code Playgroud)

你知道我该如何解决这个问题吗?

java spring spring-hateoas spring-boot

1
推荐指数
1
解决办法
1133
查看次数

如何循环和从HATEOAS _link属性检索值(例如,检索描述)?

tl; dr

我的代码从Restful GET获取了一系列javascript / json对象。如何编写代码以循环并从HATEOAS“ _link”属性检索描述(或任何值)以进行显示?

语境

我继承了一个基于Spring的小型项目,该项目跟踪服务器,软件安装等,供我们团队内部使用。它使用Angular前端和Spring / java / mysql后端实现宁静的后端。

我正在将手动编码的SQL转换为JPA和“ Spring Starter Data Rest”

目前的API

当前的手工编码SQL连接表以提供“显示友好的结果”。

Product
---------
Product ID
Product Name
Category ID

Category
---------
Category ID
Category Name
Run Code Online (Sandbox Code Playgroud)

“检索产品” sql将产品和类别连接在一起,以给出“显示友好名称”。Rest API检索带有此“类别名称”的“产品对象”。

Spring Data Rest域对象

产品

@Entity
@Table(name="products")
public class Products
{

    private static final long serialVersionUID = 5697367593400296932L;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)

    public long id;

    public String product_name;

    @ManyToOne(optional = false,cascade= CascadeType.MERGE)
    @JoinColumn(name = "category_id")
    private ProductCategory productCategory;

    public Products(){}

    public long getId() { …
Run Code Online (Sandbox Code Playgroud)

javascript hateoas angularjs spring-data-rest spring-hateoas

0
推荐指数
1
解决办法
620
查看次数