【问题标题】:How to configure Hystrix annotations from property file?如何从属性文件配置 Hystrix 注释?
【发布时间】:2016-05-07 06:04:15
【问题描述】:

我使用 Hystrix-Javanica 库通过注释应用断路器。我想用 Spring 配置中定义的属性来配置 Hystrix。由于我的应用程序使用 Spring AOP,我希望这样的事情可以工作:

@HystrixCommand(commandProperties = {
  @HystrixProperty(name = "circuitBreaker.requestVolumeThreshold", value = "${cb.requestVolumeThreshold}")
})
public boolean checkWebservice(String id) { ... }

但这失败了bad property value. property name 'circuitBreaker.requestVolumeThreshold'. Expected int value

知道如何在不硬编码值的情况下配置 Hystrix 吗?

【问题讨论】:

标签: java spring hystrix


【解决方案1】:

在 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。

【讨论】:

  • 对我来说 ConfigurationManager.install(props.getConfiguration());替换了一些重要的属性。就我而言,我必须做 ConfigurationManager.loadPropertiesFromConfiguration(props.getConfiguration());一切正常。谢谢!
猜你喜欢
  • 2012-01-29
  • 2020-12-23
  • 1970-01-01
  • 2016-03-21
  • 2019-05-25
  • 2017-02-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多