Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何从属性文件配置Hystrix注释?_Java_Spring_Hystrix - Fatal编程技术网

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

Java 如何从属性文件配置Hystrix注释?,java,spring,hystrix,Java,Spring,Hystrix,我使用hystrixjavanica库通过注释应用断路器。我想用Spring配置中定义的属性配置Hystrix。因为我的应用程序使用Spring AOP,所以我希望类似的东西能够工作: @HystrixCommand(commandProperties = { @HystrixProperty(name = "circuitBreaker.requestVolumeThreshold", value = "${cb.requestVolumeThreshold}") }) public bo

我使用hystrixjavanica库通过注释应用断路器。我想用Spring配置中定义的属性配置Hystrix。因为我的应用程序使用Spring AOP,所以我希望类似的东西能够工作:

@HystrixCommand(commandProperties = {
  @HystrixProperty(name = "circuitBreaker.requestVolumeThreshold", value = "${cb.requestVolumeThreshold}")
})
public boolean checkWebservice(String id) { ... }
但是,如果
属性值不正确,则此操作将失败。属性名称“断路器.requestVolumeThreshold”。期望的int值


有没有办法在不硬编码值的情况下配置Hystrix?

在Hystrix注释中使用属性占位符没有成功

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

hystrix.command.checkWebservice.circuitBreaker.requestVolumeThreshold=10
我添加了这个Spring配置类来将Spring属性加载到:



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

您也可以遵循此操作。。。对我来说,是ConfigurationManager.install(props.getConfiguration());替换了一些重要的属性。在我的例子中,我必须执行ConfigurationManager.loadPropertiesFromConfiguration(props.getConfiguration());一切顺利。非常感谢。
@Configuration
public class HystrixConfig {

    @Autowired
    private CommonsConfigurationFactoryBean props;

    @PostConstruct
    public void init() {
        ConfigurationManager.install(props.getConfiguration());
    }
}