SimpleIdentifiableResourceAssembler无法解析为某种类型

时间:2018-02-25 17:26:22

标签: java spring spring-boot spring-hateoas maven-dependency

我正在关注本教程:Spring HATEOAS - Basic Example

我有一个具有以下依赖项的spring boot项目:

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-rest</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger2</artifactId>
        <version>2.8.0</version>
    </dependency>
    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger-ui</artifactId>
        <version>2.8.0</version>
    </dependency>
    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-data-rest</artifactId>
        <version>2.8.0</version>
    </dependency>
    <dependency>
        <groupId>io.jsonwebtoken</groupId>
        <artifactId>jjwt</artifactId>
        <version>0.9.0</version>
    </dependency>
</dependencies>

本教程显示Spring HATEOAS提供SimpleIdentifiableResourceAssembler作为执行转换的最简单机制。

问题是我无法从org.springframework.hateoas包解析类“SimpleIdentifiableResourceAssembler”..它会抛出SimpleIdentifiableResourceAssembler cannot be resolved to a type

2 个答案:

答案 0 :(得分:1)

您的项目中没有HATEOAS依赖项。

添加

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

答案 1 :(得分:0)

即使有点晚了,但对于未来(和困惑的)开发人员来说:答案很简单,就是Class

SimpleIdentifiableResourceAssembler

到目前为止,

尚未添加到回购中。您必须自己实现功能(请参见Github issue for this question