【微服务】Nacos+openFeign服务调用调用

  1. 在启动类上添加openFeign的自动注解,配置日志级别
		<dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-openfeign</artifactId>
        </dependency>
@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients(defaultConfiguration = OpenFeignConfig.class) //全局模式可以设置局部日志级别
public class openFeignApplication {
    public static void main(String[] args) {
        SpringApplication.run(openFeignApplication.class,args);
    }

}
public class OpenFeignConfig {

    @Bean
    public Logger.Level feignLogLevel(){
        return Logger.Level.FULL;
    }
}
  1. 定义接口并实现接口生成熔断实现方法
//配置文件需要开启熔断
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";
    }
}

你可能感兴趣的:(docker,微服务,java,spring)