猬断路器不挑application.yml

问题描述 投票:0回答:1

该Hystrx断路器不从application.yml文件挑值。我需要从application.yml文件得到timeoutInMilliseconds,errorThresholdPercentage。当我运行该程序,还有是因为这些没有找到任何这些属性的影响。

import java.net.URI;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

@Service
public class BookService {
      RestTemplate restTemplate;
      //Calling the service
     @HystrixCommand
      public String readingList(int flag) {
        restTemplate = new RestTemplate();
         URI uri = URI.create("http://localhost:8090/recommended/"+flag);
        return this.restTemplate.getForObject(uri, String.class);
      }

      public String reliable(int flag) {
        return "Cloud Native Java (O'Reilly)";
      }

}

这是application.yml文件

hystrix:
  command:
    reliable:
      execution:
        isolation:
          thread:
            timeoutInMilliseconds: 6000
          strategy: SEMAPHORE
        circuitBreaker:
          errorThresholdPercentage: 70
spring-boot hystrix
1个回答
0
投票

你需要用注释@HystrixCommand(你的方法),并给command键=“可靠”。

@HystricCommand(commandKey="reliable")
public String reliable(int flag) {
    return "Cloud Native Java (O'Reilly)";
  }
© www.soinside.com 2019 - 2024. All rights reserved.