亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如果使用 spring-data-rest,找不到能夠從類型 [java.lang.String]

如果使用 spring-data-rest,找不到能夠從類型 [java.lang.String]

一只甜甜圈 2023-06-08 17:12:36
我在 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 回答
  • 0 關注
  • 148 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號