作用是定义被它所注解的注解保留多久,一共有三种策略,定义在RetentionPolicy枚举中:

package java.lang.annotation;
/**
* Annotation retention policy. The constants of this enumerated type
* describe the various policies for retaining annotations. They are used
* in conjunction with the {@link Retention} meta-annotation type to specify
* how long annotations are to be retained.
*
* @author Joshua Bloch
* @since 1.5
*/
public enum RetentionPolicy {
/**
* Annotations are to be discarded by the compiler.
   * 注解在编译时就被忽略
*/
SOURCE,
/**
* Annotations are to be recorded in the class file by the compiler
* but need not be retained by the VM at run time. This is the default
* behavior.
   * 默认是该策略,注解被编译器编译进class文件;但是不被VM运行时保留
*/
CLASS,
/**
* Annotations are to be recorded in the class file by the compiler and
* retained by the VM at run time, so they may be read reflectively.
* 一直保留到运行时 可以通过反射获取注解信息
* @see java.lang.reflect.AnnotatedElement
*/
RUNTIME
}

Spring注解之@Retention的更多相关文章

  1. spring注解源码分析--how does autowired works?

    1. 背景 注解可以减少代码的开发量,spring提供了丰富的注解功能.我们可能会被问到,spring的注解到底是什么触发的呢?今天以spring最常使用的一个注解autowired来跟踪代码,进行d ...

  2. [转]Spring注解原理的详细剖析与实现

    原文地址:http://freewxy.iteye.com/blog/1149128/ 本文主要分为三部分: 一.注解的基本概念和原理及其简单实用 二.Spring中如何使用注解 三.编码剖析spri ...

  3. spring注解式参数校验

    很痛苦遇到大量的参数进行校验,在业务中还要抛出异常或者返回异常时的校验信息,在代码中相当冗长,今天我们就来学习spring注解式参数校验. 其实就是:hibernate的validator. 开始啦. ...

  4. Spring 注解(一)Spring 注解编程模型

    Spring 注解(一)Spring 注解编程模型 Spring 系列目录(https://www.cnblogs.com/binarylei/p/10198698.html) Spring 注解系列 ...

  5. Spring 注解方式引入配置文件

    配置文件,我以两种为例,一种是引入Spring的XML文件,另外一种是.properties的键值对文件: 一.引入Spring XML的注解是@ImportResource @Retention(R ...

  6. Spring注解原理

    一.注解的基本概念和原理及其简单实用 注解(Annotation)提供了一种安全的类似注释的机制,为我们在代码中添加信息提供了一种形式化得方法,使我们可以在稍后某个时刻方便的使用这些数据(通过解析注解 ...

  7. spring注解扫描组件注册

    最近对单点系统进行微服务拆分,被各个springboot的组件注册搞得云里雾里的.(有的是通过springboot的自动配置进IOC容器的,有的是自己添加构造方法添加进IOC容器.)决定抽时间将spr ...

  8. Spring注解原理的详细剖析与实现

    本文主要分为三部分: 一. 注解的基本概念和原理及其简单实用 二. Spring中如何使用注解 三. 编码剖析spring@Resource的实现原理 一.注解的基本概念和原理及其简单实用 注解(An ...

  9. Spring 注解学习笔记

    声明Bean的注解: @Component : 组件,没有明确的角色 @Service : 在业务逻辑层(service层)使用 @Repository : 在数据访问层(dao层)使用. @Cont ...

随机推荐

  1. 利用Spring Cloud实现微服务- 熔断机制

    1. 熔断机制介绍 在介绍熔断机制之前,我们需要了解微服务的雪崩效应.在微服务架构中,微服务是完成一个单一的业务功能,这样做的好处是可以做到解耦,每个微服务可以独立演进.但是,一个应用可能会有多个微服 ...

  2. spring注解预览

    从Java5.0开始,Java开始支持注解.Spring做为Java生态中的领军框架,从2.5版本后也开始支持注解.相比起之前使用xml来配置Spring框架,使用注解提供了更多的控制Spring框架 ...

  3. MTP 写字机器

    目标 无意中看到下面视频,我打算也实现一个类似机器 视频.视频2.视频3 来源于油管Creativity Buzz的创意,顺便了解到有家AxiDraw公司在生产这种机器,淘宝上也有售卖. 想法 观看视 ...

  4. 【译】第4节---简单的Code First示例

    原文地址:http://www.entityframeworktutorial.net/code-first/simple-code-first-example.aspx 假设我们要为XYZ学校创建一 ...

  5. 原创:R包制作--windows

    1.下载安装Rtools,添加环境变量: 打开R,分别输入下面指令,看有无包错: system('g++ -v') system('where make') 2.package.skeleton()函 ...

  6. _itemmod_add

    命令._add items XXX 为目标添加一组物品 `comment`  备注 `categoryId` 组ID `entry` 物品entry `count`数量

  7. ros topic 发布一次可能会接收不到数据

    rostopic pub - /hdw_update hdw_driver/update_file_msg A B C D 系统提示: publishing and latching message ...

  8. 获取指定tag的代码

    git checkout v1.0.3 再使用ls查看就可以了

  9. JCF

    点我 补两个红黑树原理:https://www.cnblogs.com/yyxt/p/4983967.html   https://www.cnblogs.com/skywang12345/p/324 ...

  10. Python __init__.py 文件使用

    __init__.py的主要作用是: 1. Python中package的标识,不能删除 2. 定义__all__用来模糊导入 3. 编写Python代码(不建议在__init__中写python模块 ...