我使用 Hystrix-Javanica 库通过注释应用断路器。我想使用 Spring 配置中定义的属性来配置 Hystrix。由于我的应用程序使用 Spring AOP,我希望这样的东西能够工作:
@HystrixCommand(commandProperties = {
@HystrixProperty(name = "circuitBreaker.requestVolumeThreshold", value = "${cb.requestVolumeThreshold}")
})
public boolean checkWebservice(String id) { ... }
但是由于属性值错误而失败。属性名称“CircuitBreaker.requestVolumeThreshold”。期望的 int 值
有什么想法可以配置 Hystrix 而无需对值进行硬编码吗?
最佳答案
在 Hystrix 注释中使用属性占位符不起作用。
相反,我选择定义完整的配置属性,例如:
hystrix.command.checkWebservice.circuitBreaker.requestVolumeThreshold=10
我添加了这个 Spring Configuration 类来将 spring 属性加载到 Archaius 中:
@Configuration
public class HystrixConfig {
@Autowired
private CommonsConfigurationFactoryBean props;
@PostConstruct
public void init() {
ConfigurationManager.install(props.getConfiguration());
}
}
Spring Cloud Netflix可能是此设置的替代方案,但它需要 Spring Boot。
关于java - 如何从属性文件配置 Hystrix 注释?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35085617/