zoukankan      html  css  js  c++  java
  • Java基础之理解Annotation

    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();
    }
  • 相关阅读:
    Debian apt-get 无法补全
    Python 字典排序
    Python 替换字符串
    Debian 7 64位安装 wine
    Python Virtualenv 虚拟环境
    ASP.NET MVC ModelState
    Oracle存储过程写法
    利用ODBC从SQLServer向Oracle中导数据
    web自定义控件UserControl
    工作笔记
  • 原文地址:https://www.cnblogs.com/stono/p/8193504.html
Copyright © 2011-2022 走看看