@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients(defaultConfiguration = OpenFeignConfig.class)//全局模式可以设置局部日志级别
public class openFeignApplication {
public staticvoidmain(String[] args){
SpringApplication.run(openFeignApplication.class,args);}}
public class OpenFeignConfig {
@Bean
public Logger.Level feignLogLevel(){return Logger.Level.FULL;}}
定义接口并实现接口生成熔断实现方法
//配置文件需要开启熔断
feign:
hystrix:
enabled: true
@FeignClient(value ="provider",fallback = providerServiceHystrix.class)//value服务提供方的应用名 fallback设置熔断方法
public interface providerServiceClient {
@GetMapping("/demo/getTestName")//服务提供方的controller地址
public String getTestName();}
@Component
public class providerServiceHystrix implements providerServiceClient {
@Override
public String getTestName(){return"get TestName Fail";}}