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
答案 0 :(得分:0)
您需要使用@HystrixCommand()注释您的方法,并提供commandKey =“ reliable”。
@HystricCommand(commandKey="reliable")
public String reliable(int flag) {
return "Cloud Native Java (O'Reilly)";
}