Java基础之理解Annotation
学习了:https://www.cnblogs.com/mandroid/archive/2011/07/18/2109829.html
学习了:https://www.jianshu.com/p/ca7f22b4b751
@Retetion决定运行的事件;
@Target说明注解针对的对象;
jdk方面的说明:https://docs.oracle.com/javase/tutorial/java/annotations/predefined.html
可以查看@HystrixCommand源码,
// // Source code recreated from a .class file by IntelliJ IDEA // (powered by Fernflower decompiler) // package com.netflix.hystrix.contrib.javanica.annotation; import java.lang.annotation.Documented; import java.lang.annotation.ElementType; import java.lang.annotation.Inherited; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; @Target({ElementType.METHOD}) @Retention(RetentionPolicy.RUNTIME) @Inherited @Documented public @interface HystrixCommand { String groupKey() default ""; String commandKey() default ""; String threadPoolKey() default ""; String fallbackMethod() default ""; HystrixProperty[] commandProperties() default {}; HystrixProperty[] threadPoolProperties() default {}; Class<? extends Throwable>[] ignoreExceptions() default {}; ObservableExecutionMode observableExecutionMode() default ObservableExecutionMode.EAGER; }
Annotation可以包含默认值,字符串默认值是“”,对象默认值是{};
而且Annotation中可以包含Annotation数组,HystrixProperty也是一个Annotation;
// // Source code recreated from a .class file by IntelliJ IDEA // (powered by Fernflower decompiler) // package com.netflix.hystrix.contrib.javanica.annotation; import java.lang.annotation.Documented; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; @Target({ElementType.METHOD}) @Retention(RetentionPolicy.RUNTIME) @Documented public @interface HystrixProperty { String name(); String value(); }