Spring学习外传(一) @Target、@Retention、@Documented简介

这篇博客介绍了Spring中三个重要的注解:@Target、@Retention和@Documented。@Target定义了注解可以应用于哪些程序元素,@Retention指定了注解的保留策略,而@Documented则表示该注解会被包含在API文档中。通过理解这些注解的用法,可以更好地掌握Spring框架。
摘要由CSDN通过智能技术生成

怎么说呢,这三个注解是我在看SpringBoot源码的时候看到的,因为没有看过spring源码,也不清楚有没有,姑且先暂时算在spring学习里,等把spring吃透了再回来看

先来看一个一个常用注解@Controller

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.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Component
public @interface Controller {
 
	/**
	 * The value may indicate a suggestion for a logical component name,
	 * to be turned into a Spring bean in case of an autodetected component.
	 * @return the suggested component name, if any
	 */
	String value() default "";
 
}

@interface 定义注解的时候,上面有四个注解, @Component就不说了,我们看一下剩下三个注解

正片开始:

1. @Target({ElementType.TYPE}) 注解

ElementType 这个枚举类型的常量提供了一个简单的分类:注释可

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值