zoukankan      html  css  js  c++  java
  • Spring

    1.自定义注解如何实现?

    1、接口使用@interface定义

    2、通过继承以下注解,实现功能:元注解@Target,@Retention,@Documented,@Inherited 

    package org.springframework.stereotype;
    
    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;
    import org.springframework.core.annotation.AliasFor;
    
    @Target({ElementType.TYPE})
    @Retention(RetentionPolicy.RUNTIME)
    @Documented
    @Component
    public @interface Controller {
        @AliasFor(
            annotation = Component.class
        )
        String value() default "";
    }

    2.元注解的有哪些?

    元注解包含:

    @Target,
    @Retention,
    @Documented,
    @Inherited 

    具体的含义是:

    @Target 表示该注解用于什么地方,可能的 ElemenetType 参数包括: 
    * ElemenetType.CONSTRUCTOR 构造器声明 
    * ElemenetType.FIELD 域声明(包括 enum 实例) 
    * ElemenetType.LOCAL_VARIABLE 局部变量声明 
    * ElemenetType.METHOD 方法声明 
    * ElemenetType.PACKAGE 包声明 
    * ElemenetType.PARAMETER 参数声明 
    * ElemenetType.TYPE 类,接口(包括注解类型)或enum声明 
     
    @Retention 表示在什么级别保存该注解信息。可选的 RetentionPolicy 参数包括: 
    * RetentionPolicy.SOURCE 注解将被编译器丢弃 
    * RetentionPolicy.CLASS 注解在class文件中可用,但会被VM丢弃 
    * RetentionPolicy.RUNTIME VM将在运行期也保留注释,因此可以通过反射机制读取注解的信息。 
     
    @Documented 将此注解包含在 javadoc 中 
     
    @Inherited 允许子类继承父类中的注解
  • 相关阅读:
    nginx+keepalived实现高可用
    zookeeper集群和安装dubbo的管控台
    常见设计模式的解析和实现(C++)
    sed的工作原理(pattern space 和 hold space)
    sed学习笔记
    C++协助破案问题
    C++中extern “C”含义深层探索
    阿里巴巴笔试第28题
    阿里巴巴集团2014校园招聘笔试题(研发工程师--北邮站)
    淘宝数据魔方技术架构解析
  • 原文地址:https://www.cnblogs.com/frankcui/p/14347350.html
Copyright © 2011-2022 走看看