我在 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 }}但是當(dāng)我嘗試通過提供的鏈接獲取一個特定資源時,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]我試圖創(chuàng)建轉(zhuǎn)換器并通過這種方式注冊它們:@Componentpublic class WebConfig implements WebMvcConfigurer { @Override public void addFormatters(FormatterRegistry registry) { System.out.println("^^^^^^^^^^^^^^^^^^^^^^^^^^^"); registry.addConverter(new KeyToStringConverter()); registry.addConverter(new StringToKeyConverter()); }}我看到了打印輸出,所以代碼已經(jīng)執(zhí)行,盡管我在轉(zhuǎn)換器內(nèi)部的打印輸出沒有。我有簡單的實(shí)體: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;這些錯過的轉(zhuǎn)換器是什么?我該如何注冊它們?
添加回答
舉報
0/150
提交
取消