Rest FaignClient正在更改传递给它的LocalDate的格式

Rest FaignClient正在更改传递给它的LocalDate的格式,rest,spring-cloud-feign,localdate,Rest,Spring Cloud Feign,Localdate,我的应用程序中有一个@FeignClient: @FeignClient(name="${mongo.service.id}", url="${mongo.service.url}") public interface MongoCustomerClaimInterface { @GetMapping(path = "/api/customerClaim/countClaims/{businessDate}") List

我的应用程序中有一个
@FeignClient

@FeignClient(name="${mongo.service.id}", url="${mongo.service.url}")
public interface MongoCustomerClaimInterface {
    @GetMapping(path = "/api/customerClaim/countClaims/{businessDate}")
    List<TransactionClaimStatusData> countClaimsByStatusToBusinessDate(
    @PathVariable @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) 
    LocalDate businessDate);
}
调用将生成
404
错误和日志:

2020-24-02 18:10:25.433 INFO  DashboardServiceImpl - formattedDate: 2020-02-23
2020-24-02 18:10:25.440 DEBUG
RequestMappingHandlerMapping:
Looking up handler method for path /api/customerClaim/countClaims/2/23/20
RequestMappingHandlerMapping:
Did not find handler method for [/api/customerClaim/countClaims/2/23/20]
虽然我以
yyyy-mm-dd
格式传递日期,但它将匹配:

  • @DateTimeFormat(iso=DateTimeFormat.iso.DATE)
  • 佯装以某种方式更改日期,然后找不到匹配的url

我怎样才能防止Faign这样做,并配置一个统一的格式化程序呢?

显然,Faign不能处理所有的SpringMvc注释
@DateTimeFormat
是一个SpringMvc注释,而不是一个伪装的客户端注释。 我通过做几件事来解决这个问题:

  • 在我的MvcConfig类中创建了一个MessageConvertersConfiguration类。 在其中,我创建了一个LocalDate&LocalDateTime转换器bean,并将其添加到该配置程序在http消息到达时使用的转换器列表中:
  • 最后,我将配置属性添加到我的佯装客户端:
  • @FeignClient(name=“${mongo.service.id}”,url=“${mongo.service.url}”,configuration=FeignConfig.class)
    公共接口MongoCustomerClaimInterface{
    @GetMapping(路径=“/api/customerClaim/countClaimsByStatusToBusinessDate/{businessDate}”)
    列出countClaimsByStatusToBusinessDate(@PathVariable@DateTimeFormat(iso=DateTimeFormat.iso.DATE)LocalDate businessDate);
    }
    
    如何定义newMappingJackson2HttpMessageConverter?
    2020-24-02 18:10:25.433 INFO  DashboardServiceImpl - formattedDate: 2020-02-23
    2020-24-02 18:10:25.440 DEBUG
    RequestMappingHandlerMapping:
    Looking up handler method for path /api/customerClaim/countClaims/2/23/20
    RequestMappingHandlerMapping:
    Did not find handler method for [/api/customerClaim/countClaims/2/23/20]
    
    @Configuration
    public class MvcConfig {
        
        @Configuration
        @EnableWebMvc
        public class MessageConvertersConfiguration implements WebMvcConfigurer {
            @Override
            public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
              converters.add(new MappingJackson2HttpMessageConverter(localDateTimeConverter()));
            }
    
            @Bean
            public ObjectMapper localDateTimeConverter() {
                ObjectMapper mapper = new ObjectMapper();
                SimpleModule localDateTimeModule = new SimpleModule();
    
                DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("dd-MM-yyyy'T'HH:mm:ss");
                localDateTimeModule.addDeserializer(LocalDateTime.class, new LocalDateTimeDeserializer(dateTimeFormatter));
                localDateTimeModule.addSerializer(LocalDateTime.class, new LocalDateTimeSerializer(dateTimeFormatter));
    
                DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
                localDateTimeModule.addDeserializer(LocalDate.class, new LocalDateDeserializer(dateFormatter));
                localDateTimeModule.addSerializer(LocalDate.class, new LocalDateSerializer(dateFormatter));
    
                mapper.registerModules(localDateTimeModule);
    
                return mapper;
            }
        }
    }
    
    @Configuration
    public class FeignConfig {
        @Bean
        public Contract feignContract() {
            return new SpringMvcContract();
        }
    }
    
    @FeignClient(name="${mongo.service.id}", url="${mongo.service.url}", configuration = FeignConfig.class)
    public interface MongoCustomerClaimInterface {
        @GetMapping(path = "/api/customerClaim/countClaimsByStatusToBusinessDate/{businessDate}")
        List<TransactionClaimStatusData> countClaimsByStatusToBusinessDate(@PathVariable @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate businessDate);
    }