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