如何从属性文件配置 Hystrix 注释?

Tim*_*aer 2 java spring hystrix

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

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

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

任何想法如何在不硬编码值的情况下配置 Hystrix?

Tim*_*aer 5

在 Hystrix 注释中使用属性占位符不起作用。

相反,我选择定义完整的配置属性,例如:

hystrix.command.checkWebservice.circuitBreaker.requestVolumeThreshold=10
Run Code Online (Sandbox Code Playgroud)

我添加了这个 Spring Configuration 类来将 spring 属性加载到Archaius 中

@Configuration
public class HystrixConfig {

    @Autowired
    private CommonsConfigurationFactoryBean props;

    @PostConstruct
    public void init() {
        ConfigurationManager.install(props.getConfiguration());
    }
}
Run Code Online (Sandbox Code Playgroud)

Spring Cloud Netflix可能是此设置的替代方案,但它需要 Spring Boot。