All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.lframework.starter.cloud.config.CloudConfiguration Maven / Gradle / Ivy

There is a newer version: 3.1.4
Show newest version
package com.lframework.starter.cloud.config;

import com.lframework.starter.common.constants.StringPool;
import feign.Retryer;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.cloud.openfeign.FeignFormatterRegistrar;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.convert.converter.Converter;

@Configuration
public class CloudConfiguration {

  @Autowired
  private ObjectFactory messageConverters;

  @Bean
  public Retryer retryer() {

    // 不进行重试
    return Retryer.NEVER_RETRY;
  }

  @Bean
  public FeignFormatterRegistrar localDataTimeFormatRegister() {
    return registry -> registry.addConverter(new Converter() {
      @Override
      public String convert(LocalDateTime source) {
        return source.format(DateTimeFormatter.ofPattern(StringPool.DATE_TIME_PATTERN));
      }
    });
  }

  @Bean
  public FeignFormatterRegistrar localDataFormatRegister() {
    return registry -> registry.addConverter(new Converter() {
      @Override
      public String convert(LocalDate source) {
        return source.format(DateTimeFormatter.ofPattern(StringPool.DATE_PATTERN));
      }
    });
  }

  @Bean
  public FeignFormatterRegistrar localTimeFormatRegister() {
    return registry -> registry.addConverter(new Converter() {
      @Override
      public String convert(LocalTime source) {
        return source.format(DateTimeFormatter.ofPattern(StringPool.TIME_PATTERN));
      }
    });
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy