Весеннее Облако Hystrix: fallbackMethod не работает - PullRequest
0 голосов
/ 12 октября 2019

почему мой запасной метод не работает ??

если я отключу поставщика услуг, вернем java.net.ConnectException: соединение отклонено: connect

mian метод:

@EnableCircuitBreaker
@SpringBootApplication
public class ConsumerApplication {

    @Bean
    @LoadBalanced
    RestTemplate restTemplate() {
        return new RestTemplate();
    }


    /**
     * 更改负载均衡策略
     *
     * @return IRule
     */
    @Bean
    public IRule irule() {
        return new RandomRule();
    }

    public static void main(String[] args) {
        SpringApplication.run(ConsumerApplication.class, args);
    }
}

HelloService:

@Service
public class HelloService {
    @Autowired
    private RestTemplate restTemplate;

    @HystrixCommand(fallbackMethod = "helloFallBack")
    public String helloService() {
        System.out.println("run consumer-hello-ribbon");
        return restTemplate.getForEntity("http://PROVIDER-SERVICE/hello", String.class).getBody();
    }

    public String helloFallBack() {
        return "error";
    }
}

HelloController:

@RestController
public class HelloController {

    @Autowired
    private HelloService helloService;

    @GetMapping(value = "/consumer-hello-ribbon")
    public String hello() {
        return helloService.helloService();
    }
}

как я могу решить эту проблему? пожалуйста, помогите мне, спасибо

...