簡體   English   中英

spring-cloud-schema-registry-client 沒有轉換為 Avro,我得到 org.springframework.http.converter.HttpMessageNotWritableException

[英]spring-cloud-schema-registry-client does not convert to Avro and I get org.springframework.http.converter.HttpMessageNotWritableException

我的目標是讓 Spring 自動從 POJO 和任何 Avro 模式文件自動編組對 Avro 格式的響應和請求。 幾天來,我試圖讓 spring-cloud-schema-registry-client 自動序列化/反序列化控制器作為響應發回的應用程序/avro 消息,但都無濟於事。 該請求帶有 Accept 標頭“application/avro”(我也嘗試過 application/emp.v1+avro 和其他組合)。

無論我嘗試什么,響應消息都不會被spring cloud AvroSchemaMessageConverter自動反序列化。 根據他們的文檔,應該從 POJO 中自動推斷出 Avro 模式,並且應該在 Avro 中開箱即用地發送回響應。

我正在使用的依賴項是

   <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-schema-registry-client</artifactId>
      <version>1.1.5</version>
  </dependency>

我的 application.yml 文件有 -

spring:
   cloud:
    stream:
      bindings:
        output:
          contentType: application/*+avro
    schema:
      avro:
        dynamicSchemaGenerationEnabled: true

有人可以幫我理解為什么這不起作用而且我不斷收到錯誤消息 -

org.springframework.http.converter.HttpMessageNotWritableException: No converter for [class java.util.Arrays$ArrayList]

我需要顯式注冊架構嗎? 例如,我正在返回一個員工 POJO 列表。 如果需要,我可以嘗試使用jackson- dataformats 從 Employee POJO 生成 Avro 模式,然后使用 AvroConverter bean 手動注冊它。 但據我了解,這應該由 spring-cloud-schema-registry 開箱即用地完成。

附加信息:我的控制器返回一個員工 POJO 列表,例如

ResponseEntity<List<Employee>>

我在主類中使用了@EnableSchemRegistryClient 和@SpringBootApplication。

在我的測試方法中,我正在使用:

        MvcResult result = mockMvc
            .perform(MockMvcRequestBuilders.get(url)
                    //.contentType(MediaType.APPLICATION_JSON_VALUE)
                    .accept("application/avro"))
                    .andExpect(content().contentType("application/avro")) 

我不再是 Spring 成員,並且我相信不再維護模式注冊表。 但它從來沒有打算與控制器一起序列化/反序列化有效負載。 它旨在與 Spring Cloud Stream 自己的序列化機制(版本 1.x)一起使用。

恐怕在這種情況下,如果您不進行一些修補來構建一個序列化程序,該序列化程序會查找給定模式的注冊表並來回序列化它,那么在這種情況下它是行不通的。 請注意,您還需要一個帶有架構 FQN 的標頭才能查詢注冊表,並且必須緩存它以免影響您的應用程序。

希望 Spring 團隊的某個人可以對此提供一些更好的見解。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM