我在 spring-data-gcp-datastore 之上使用 spring-data-rest。我正在尝试使用 HAL 浏览器探索我的资源。最初它工作正常,所以我看到了我的元素:{ "_embedded": { "configurations": [ { "data": "{\n \"test\": \"768\",\n \"test2\": 5\n}", "_links": { "self": { "href": "http://localhost:8083/configurations/Key%7BprojectId=test,%20namespace=,%20path=%5BPathElement%7Bkind=configuration,%20id=null,%20name=k%7D%5D%7D" }, "configuration": { "href": "http://localhost:8083/configurations/Key%7BprojectId=test,%20namespace=,%20path=%5BPathElement%7Bkind=configuration,%20id=null,%20name=k%7D%5D%7D" } } } ] }, "_links": { "self": { "href": "http://localhost:8083/configurations{?page,size,sort}", "templated": true }, "profile": { "href": "http://localhost:8083/profile/configurations" } }, "page": { "size": 20, "totalElements": 1, "totalPages": 1, "number": 0 }}但是当我尝试通过提供的链接获取一个特定资源时,http://localhost:8083/configurations/Key%7BprojectId=test,%20namespace=,%20path=%5BPathElement%7Bkind=configuration,%20id=null,%20name=k%7D%5D%7D我遇到了一个错误: org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.lang.String] to type [com.google.cloud.datastore.Key]我试图创建转换器并通过这种方式注册它们:@Componentpublic class WebConfig implements WebMvcConfigurer { @Override public void addFormatters(FormatterRegistry registry) { System.out.println("^^^^^^^^^^^^^^^^^^^^^^^^^^^"); registry.addConverter(new KeyToStringConverter()); registry.addConverter(new StringToKeyConverter()); }}我看到了打印输出,所以代码已经执行,尽管我在转换器内部的打印输出没有。我有简单的实体:package com.test.appconfig.datastore.entities;import lombok.Data;import com.google.cloud.datastore.Key;import org.springframework.cloud.gcp.data.datastore.core.mapping.Entity;import org.springframework.data.annotation.Id;这些错过的转换器是什么?我该如何注册它们?
添加回答
举报
0/150
提交
取消