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

org.zodiac.autoconfigure.feign.annotation.FeignConsumerConfigurerRegistrar Maven / Gradle / Ivy

There is a newer version: 1.6.8
Show newest version
package org.zodiac.autoconfigure.feign.annotation;

import org.slf4j.Logger;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.EnvironmentAware;
import org.springframework.context.annotation.AnnotationBeanNameGenerator;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.env.Environment;
import org.springframework.core.type.AnnotationMetadata;
import org.zodiac.autoconfigure.feign.FeignContextAutoConfiguration;
import org.zodiac.commons.logging.SmartSlf4jLoggerFactory;

public class FeignConsumerConfigurerRegistrar implements ImportBeanDefinitionRegistrar, EnvironmentAware {

    protected final Logger log = SmartSlf4jLoggerFactory.getLogger(getClass());

    private Environment environment;

    protected FeignConsumerConfigurerRegistrar() {
        super();
    }

    @Override
    public void setEnvironment(Environment environment) {
        this.environment = environment;
    }

    /**
     * Spring cloud auto configuration should not be affected.
     * 
     * 
*
    *
  • org.springframework.cloud.openfeign.ribbon.DefaultFeignLoadBalancedConfiguration
  • *
  • org.springframework.cloud.openfeign.ribbon.HttpClientFeignLoadBalancedConfiguration
  • *
  • org.springframework.cloud.openfeign.ribbon.OkHttpFeignLoadBalancedConfiguration
  • *
*
*/ @Override public void registerBeanDefinitions(AnnotationMetadata metadata, BeanDefinitionRegistry registry) { /*Check enabled configuration*/ if (!FeignConsumersRegistrar.isEnableConfiguration(environment)) { log.warn("No enabled SpringBoot and SpringCloud feign auto configurer!"); return; } /*Not SpringCloud + Feign*/ if (!FeignConsumersRegistrar.hasSpringCloudFeignClass()) { //BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(FeignConsumerAutoConfiguration.class); BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(obtainFeignConsumerConfigurationType()); AbstractBeanDefinition definition = builder.getBeanDefinition(); String beanName = AnnotationBeanNameGenerator.INSTANCE.generateBeanName(definition, registry); registry.registerBeanDefinition(beanName, definition); } } protected Class obtainFeignConsumerConfigurationType() { return FeignContextAutoConfiguration.class; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy