简体   繁体   English

Hateoas - 找不到适合 Link(java.lang.String) 的构造函数

[英]Hateoas - No suitable constructor found for Link(java.lang.String)

For a REST API, in the controller I'm applying hateoas.对于 REST API,在 controller 中我应用了 hateoas。 When adding the part of Link in the methods, I get the follow error: Cannot resolve constructor 'Link(String)'在方法中添加链接部分时,出现以下错误: Cannot resolve constructor 'Link(String)'

In the pom.xml:在 pom.xml 中:

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

The code is as follows:代码如下:

 @GetMapping
public @ResponseBody ResponseEntity<List<UserResponseDTO>> get() {

    // Retrieve users
    List<UserResponseDTO> responseDTOS = new ArrayList<>();
    List<User> users = userService.getUsers();

    // Convert to responseDTOS
    for (User user : users) {
        UserResponseDTO userResponseDTO = new UserResponseDTO(user.getId(), user.getFirstName(), user.getLastName());

        Link get = new Link("http://localhost:8081/user/").withRel("GET");

        userResponseDTO.add(get);
        responseDTOS.add(userResponseDTO);
    }

    return new ResponseEntity<>(responseDTOS, HttpStatus.OK);
}

Does anyone know how to solve this?有谁知道如何解决这个问题?

Link(String) is deprecated and may be removed in some new version. Link(String)已弃用,可能会在某些新版本中删除。 Also Link(String) uses the protected access modifier meaning you should access it only from the same package.此外, Link(String)使用受保护的访问修饰符,这意味着您只能从同一个 package 访问它。

You can still create the Link using the of static method which by the way is defined with public access modifier.您仍然可以使用 static 方法创建Link of该方法是使用公共访问修饰符定义的。

So it should be所以应该是

Link get = Link.of("http://localhost:8081/user/").withRel("GET");

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 构造函数的参数 0 需要一个类型为“java.lang.String”的 bean,但找不到 - Parameter 0 of constructor in required a bean of type 'java.lang.String' that could not be found com.din.OSS中的构造函数的参数0需要找不到类型为&#39;java.lang.String&#39;的bean - Parameter 0 of constructor in com.din.OSS required a bean of type 'java.lang.String' that could not be found com.project.api.graphql.service.GraphQLService 中构造函数的参数 0 需要一个无法找到的“java.lang.String”类型的 bean - Parameter 0 of constructor in com.project.api.graphql.service.GraphQLService required a bean of type 'java.lang.String' that could not be found 在类型 [java.lang.String] 上找不到属性 [id] - Property [id] not found on type [java.lang.String] 类需要一个找不到的“java.lang.String”类型的 bean - Class required a bean of type 'java.lang.String' that could not be found 找不到能够从 [java.lang.String] 类型转换为 [java.util.LinkedHashMap] 类型的转换器<java.lang.String, java.lang.String> ] - No converter found capable of converting from type [java.lang.String] to type [java.util.LinkedHashMap<java.lang.String, java.lang.String>] ElasticSearch SpringBoot + Spring数据:java.lang.IllegalStateException:在接口上找不到合适的构造函数 - ElasticSearch SpringBoot+Spring Data: java.lang.IllegalStateException: No suitable constructor found on interface 如何修复“类型不匹配。必需:java.lang.String Found:kotlin.String” - How to fix "Type mismatch. Required: java.lang.String Found: kotlin.String" PCF-找不到能够从[java.util.LinkedHashMap类型进行转换的转换器 <?, ?> ]键入[java.lang.String] - PCF - No converter found capable of converting from type [java.util.LinkedHashMap<?, ?>] to type [java.lang.String] 错误:EL1004E:方法调用:在类型 com.jcraft.jsch.ChannelSftp$2 上找不到方法重命名(java.lang.String,java.lang.String) - Error: EL1004E: Method call: Method rename(java.lang.String,java.lang.String) cannot be found on type com.jcraft.jsch.ChannelSftp$2
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM