mirror of
				https://github.com/dromara/RuoYi-Vue-Plus.git
				synced 2025-11-04 16:23:42 +08:00 
			
		
		
		
	fix Feign 熔断不生效 bug
This commit is contained in:
		@@ -3,14 +3,13 @@ package com.ruoyi;
 | 
			
		||||
import org.springframework.boot.SpringApplication;
 | 
			
		||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
 | 
			
		||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
 | 
			
		||||
import org.springframework.cloud.openfeign.EnableFeignClients;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * 启动程序
 | 
			
		||||
 * 
 | 
			
		||||
 * @author ruoyi
 | 
			
		||||
 */
 | 
			
		||||
@EnableFeignClients
 | 
			
		||||
 | 
			
		||||
@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class })
 | 
			
		||||
public class RuoYiApplication
 | 
			
		||||
{
 | 
			
		||||
 
 | 
			
		||||
@@ -207,4 +207,6 @@ feign:
 | 
			
		||||
    response:
 | 
			
		||||
      enabled: true
 | 
			
		||||
  okhttp:
 | 
			
		||||
    enabled: true
 | 
			
		||||
  hystrix:
 | 
			
		||||
    enabled: true
 | 
			
		||||
@@ -2,11 +2,16 @@ package com.ruoyi.demo.feign.fallback;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
import com.ruoyi.demo.feign.FeignTestService;
 | 
			
		||||
import lombok.extern.slf4j.Slf4j;
 | 
			
		||||
import org.springframework.stereotype.Component;
 | 
			
		||||
 | 
			
		||||
@Slf4j
 | 
			
		||||
@Component
 | 
			
		||||
public class FeignTestFallback implements FeignTestService {
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public String search(String wd) {
 | 
			
		||||
        return null;
 | 
			
		||||
        log.error("fallback");
 | 
			
		||||
        return "报错啦";
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,10 +1,12 @@
 | 
			
		||||
package com.ruoyi.framework.config;
 | 
			
		||||
 | 
			
		||||
import feign.*;
 | 
			
		||||
import feign.hystrix.HystrixFeign;
 | 
			
		||||
import okhttp3.ConnectionPool;
 | 
			
		||||
import okhttp3.OkHttpClient;
 | 
			
		||||
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
 | 
			
		||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
 | 
			
		||||
import org.springframework.cloud.openfeign.EnableFeignClients;
 | 
			
		||||
import org.springframework.cloud.openfeign.FeignAutoConfiguration;
 | 
			
		||||
import org.springframework.cloud.openfeign.support.SpringMvcContract;
 | 
			
		||||
import org.springframework.context.annotation.Bean;
 | 
			
		||||
@@ -12,6 +14,7 @@ import org.springframework.context.annotation.Configuration;
 | 
			
		||||
 | 
			
		||||
import java.util.concurrent.TimeUnit;
 | 
			
		||||
 | 
			
		||||
@EnableFeignClients
 | 
			
		||||
@Configuration
 | 
			
		||||
@ConditionalOnClass(Feign.class)
 | 
			
		||||
@AutoConfigureBefore(FeignAutoConfiguration.class)
 | 
			
		||||
@@ -29,7 +32,7 @@ public class FeignConfig {
 | 
			
		||||
 | 
			
		||||
    @Bean
 | 
			
		||||
    public Feign.Builder feignBuilder() {
 | 
			
		||||
        return Feign.builder();
 | 
			
		||||
        return HystrixFeign.builder();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Bean
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user