通过引入支持注解,可以更容易的使用Hystrix。
@HystrixCommand:
1)此注解表示此方法是hystrix方法,其中fallbackMethod定义回退方法的名称,可以为当前方法Hystrix默认命令属性。
2)也就是使用注解的形式配置Hystrix,简化开发代码编写,更专注于功能的实现。
3)HystrixCommandAspect 通过AOP拦截所有的@HystrixCommand注解的方法,从而使得@HystrixCommand能够集成到Spring boot中。
@EnableCircuitBreaker:等同于@EnableHystrix,启动断路器,开启Hystrix。EnableCircuitBreakerImportSelector是SpringFactoryImportSelector子类。此类在初始化后,会执行selectImports(AnnotationMetadata metadata)的方法。此方法会根据注解启动的注解(这里指@EnableCircuitBreaker)从spring.factories文件中获取其配置需要初始化@Configuration类(这里是org.springframework.cloud.netflix.hystrix.HystrixCircuitBreakerConfiguration),从而最终初始化HystrixCommandAspect 类,从而实现拦截HystrixCommand的功能。
@DefaultProperties:@DefaultProperties是类(类型)级别的注释,允许为当前类指定Hystrix默认命令属性,如groupKey,threadPoolKey,commandProperties,threadPoolProperties,ignoreExceptions和raiseHystrixExceptions。
使用此注解指定的属性,会覆盖在配置文件中定义的默认配置,也将在类中使用@HystrixCommand注解的方法中公用,除非某个方法明确使用相应的@HystrixCommand参数来指定这些属性。
大概总结就是这样,可能有点乱。
参考文章
https://blog.csdn.net/sdmjhca/article/details/77948511
https://blog.csdn.net/hry2015/article/details/78577695
https://www.cnblogs.com/duan2/p/9307217.html
https://www.cnblogs.com/acmez/p/13627053.html