org.yes.tools.config.FeignAutoConfig Maven / Gradle / Ivy
package org.yes.tools.config;
import com.alibaba.cloud.sentinel.feign.SentinelFeignAutoConfiguration;
import com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.BlockExceptionHandler;
import com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.RequestOriginParser;
import com.fasterxml.jackson.databind.ObjectMapper;
import feign.Feign;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;
import org.yes.tools.ext.SentinelFeign;
import org.yes.tools.handle.UrlBlockHandler;
import org.yes.tools.parser.HeaderRequestOriginParser;
/**
* sentinel 配置
*
* @author Co.
* @date 2023/10/24 10:24
*/
@Configuration(proxyBeanMethods = false)
@AutoConfigureBefore(SentinelFeignAutoConfiguration.class)
public class FeignAutoConfig {
@Bean
@Scope("prototype")
@ConditionalOnMissingBean
@ConditionalOnProperty(name = "feign.sentinel.enabled")
public Feign.Builder feignSentinelBuilder() {
return SentinelFeign.builder();
}
@Bean
@ConditionalOnMissingBean
public BlockExceptionHandler blockExceptionHandler(ObjectMapper objectMapper) {
return new UrlBlockHandler(objectMapper);
}
@Bean
public RequestOriginParser requestOriginParser() {
return new HeaderRequestOriginParser();
}
}