Support `ClientHttpMessageConvertersCustomizer` in `FeignHttpMessageConverters` for Spring Boot 4.0 Alignment

Đang mở
#1,293 6 bình luận 1 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
65/100
Loại issue
Tính năng
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Ít trao đổi
Công nghệ
java, spring, spring-boot
Lĩnh vực
api, backend

Hướng nghiên cứu

Bắt đầu trong FeignHttpMessageConverters.java, đặc biệt là constructor và initConvertersIfRequired(), rồi kiểm tra ClientHttpMessageConvertersCustomizer khác với Feign HttpMessageConverterCustomizer hiện có như thế nào. Theo dõi luồng và thứ tự của ClientBuilder trước khi quyết định nên đặt các client customizers ở đâu. Được xem là hoàn tất khi các client customizers của Spring Boot 4 tác động đến các converter của Feign mà không làm hỏng hành vi hiện có của converter và Feign-customizer.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

waiting-for-triage

Is your feature request related to a problem? Please describe.
With the architectural changes in Spring Boot 4.0 (as detailed in spring-projects/spring-boot#48310), the configuration of HTTP Message Converters has shifted from collecting all HttpMessageConverter beans from the context to using dedicated customizers (ClientHttpMessageConvertersCustomizer for clients and ServerHttpMessageConvertersCustomizer for servers).

Currently, FeignHttpMessageConverters in Spring Cloud OpenFeign constructs the converter list by collecting raw HttpMessageConverter<?> beans from the ObjectProvider and applying its own Feign-specific org.springframework.cloud.openfeign.support.HttpMessageConverterCustomizer.

This creates an inconsistency in the ecosystem. If I configure a converter using the standard Spring Boot 4.0 ClientHttpMessageConvertersCustomizer (intended for RestClient and RestTemplate), OpenFeign ignores it. I am forced to either:

  1. Define the converter as a raw @Bean (which Spring Boot 4.0 discourages for auto-configuration context pollution).
  2. Duplicate the configuration using the Feign-specific HttpMessageConverterCustomizer.

Describe the solution you'd like
FeignHttpMessageConverters should detect and apply ClientHttpMessageConvertersCustomizer beans from the application context. This would allow a single point of configuration for all HTTP clients (Feign, RestClient, and RestTemplate) in a Spring Boot 4.0 application.

In FeignHttpMessageConverters.java, specifically within the initConvertersIfRequired() method, the logic builds an HttpMessageConverters instance using HttpMessageConverters.ClientBuilder. Since ClientHttpMessageConvertersCustomizer is designed to customize HttpMessageConverters, it seems natural to apply these customizers there.

Proposed logic change conceptually:

public class FeignHttpMessageConverters {
    
    // Inject ClientHttpMessageConvertersCustomizer provider
    private final ObjectProvider<ClientHttpMessageConvertersCustomizer> clientCustomizers;

    // ... constructor ...

    private void initConvertersIfRequired() {
       if (this.converters == null) {
          // ... existing builder logic ...
          
          HttpMessageConverters hmc = builder.build();
          
          // PROPOSED CHANGE: Apply Spring Boot Client Customizers
          if (this.clientCustomizers != null) {
              this.clientCustomizers.orderedStream().forEach(customizer -> customizer.customize(hmc));
          }

          // Continue with existing logic
          hmc.forEach(converter -> converters.add(converter));
          customizers.forEach(customizer -> customizer.accept(this.converters));
       }
    }
}

Describe alternatives you've considered

  • Current Workaround: Defining a separate @Bean for org.springframework.cloud.openfeign.support.HttpMessageConverterCustomizer that duplicates the logic present in my ClientHttpMessageConvertersCustomizer.
  • Global Bean: Defining the converter as a global @Bean marked with @Primary. However, as mentioned in the linked Spring Boot issue, relying on collecting beans from the context is being revisited and might not be the preferred way forward for separate client/server configurations.

Additional context
References:

  • Spring Boot Issue: Revisit HttpMessageConverters auto-configuration #48310
  • Current implementation of FeignHttpMessageConverters relies on:
    public FeignHttpMessageConverters(ObjectProvider<HttpMessageConverter<?>> messageConverters,
          ObjectProvider<HttpMessageConverterCustomizer> customizers) {
       this.messageConverters = messageConverters;
       this.customizers = customizers;
    }
    
    It misses the ClientHttpMessageConvertersCustomizer which is now the standard for client-side configuration in Boot 4.
Ngôn ngữ chính
Java
Star
1.3k
Fork
834
Merge trung bình
1 ngày 15 giờ
Pull request đã merge (30 ngày)
14

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của spring-cloud/spring-cloud-openfeign

Tất cả issue của spring-cloud/spring-cloud-openfeign

Issue tương tự

Thêm issue về Java

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.