SpringBoot 三、@SpringBootApplication 注解

本文详细探讨了SpringBoot的@SpringBootApplication注解,包括@Target、@Retention、@Documented、@Inherited等元注解的作用。此外,还介绍了@SpringBootConfiguration、@EnableAutoConfiguration和@ComponentScan的功能,讲解了自动配置的幕后机制如SpringFactoriesLoader的工作原理。@ComponentScan用于扫描并加载组件,建议将其放在项目根目录的启动类上。
摘要由CSDN通过智能技术生成

新建springboot项目后,项目自动生成一个Application 类 ,今天我们主要讲下SpringBootApplication注解

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class BootApplication {
    public static void main(String[] args) {
        SpringApplication.run(BootApplication.class, args);
    }
}

点进去查看源码看到上面有好多个注解

在这里插入图片描述

@Target :

Indicates the contexts in which an annotation type is applicable。指示所适用的注解类型。这里ElementType.TYPE指的是适用于类。

@Retention:

Indicates how long annotations with the annotated type are to be retained. 指示注解类型的注解要保留多久。这里的保留策略是RUNTIME:编译器将把注解记录在类文件中,在运行时 VM 将保留注解,因此可以反射性地读取。

@Documented࿱

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

大鹏小站

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值