@SpringBootApplication注解

这篇具有很好参考价值的文章主要介绍了@SpringBootApplication注解。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

 

 启动类的

@SpringBootApplication

//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package org.springframework.boot.autoconfigure;

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;
import org.springframework.beans.factory.support.BeanNameGenerator;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.context.TypeExcludeFilter;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.FilterType;
import org.springframework.context.annotation.ComponentScan.Filter;
import org.springframework.core.annotation.AliasFor;

@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@SpringBootConfiguration
@EnableAutoConfiguration
@ComponentScan(
    excludeFilters = {@Filter(
    type = FilterType.CUSTOM,
    classes = {TypeExcludeFilter.class}
), @Filter(
    type = FilterType.CUSTOM,
    classes = {AutoConfigurationExcludeFilter.class}
)}
)
public @interface SpringBootApplication {
    @AliasFor(
        annotation = EnableAutoConfiguration.class
    )
    Class<?>[] exclude() default {};

    @AliasFor(
        annotation = EnableAutoConfiguration.class
    )
    String[] excludeName() default {};

    @AliasFor(
        annotation = ComponentScan.class,
        attribute = "basePackages"
    )
    String[] scanBasePackages() default {};

    @AliasFor(
        annotation = ComponentScan.class,
        attribute = "basePackageClasses"
    )
    Class<?>[] scanBasePackageClasses() default {};

    @AliasFor(
        annotation = ComponentScan.class,
        attribute = "nameGenerator"
    )
    Class<? extends BeanNameGenerator> nameGenerator() default BeanNameGenerator.class;

    @AliasFor(
        annotation = Configuration.class
    )
    boolean proxyBeanMethods() default true;
}

其中@SpringBootConfiguration

//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package org.springframework.boot;

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.context.annotation.Configuration;
import org.springframework.core.annotation.AliasFor;
import org.springframework.stereotype.Indexed;

@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Configuration
@Indexed
public @interface SpringBootConfiguration {
    @AliasFor(
        annotation = Configuration.class
    )
    boolean proxyBeanMethods() default true;
}
@SpringBootConfiguration 之上有 @Configuration

所以加上@SpringBootApplication之后,会被当做配置类

--------------------------------------------------------------------------------

@Configuration

//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package org.springframework.context.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;
import org.springframework.core.annotation.AliasFor;
import org.springframework.stereotype.Component;

@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Component
public @interface Configuration {
    @AliasFor(
        annotation = Component.class
    )
    String value() default "";

    boolean proxyBeanMethods() default true;
}
其上有@Component 注解,所以 有@Configuration注解的类会创建bean对象交由spring容器去管理
@AliasFor(
    annotation = Component.class
)
String value() default "";

@Configuration注解 的value属性之上有注解@AliasFor( annotation = Component.class )

在使用@Configuration(value="s"),该属性的值将传给@Component的value属性,相当于有了@Component(value='s')的效果

--------------------------------------------------------------------------------

@SpringBootApplication 之上的@EnableAutoConfiguration

开启自动配置


 

 

@SpringBootApplication 之上的 @ComponentScan 开启组件扫描

Spring 自动扫描指定的基础包以及其子包中的所有类,并将被带有特定注解标记的类自动注册到 Spring 上下文中成为一个 Bean(basePackages 未指定,默认扫描当前包及子包)

在@SpringBootApplication 中  其属性scanBasePackages 为@ComponentScan注解的 basePackages属性的别名,@SpringBootApplication(scanBasePackages=S) 就有@ComponentScan(basePackages=S)的效果文章来源地址https://www.toymoban.com/news/detail-422129.html

@AliasFor(
    annotation = ComponentScan.class,
    attribute = "basePackages"
)
String[] scanBasePackages() default {};

到了这里,关于@SpringBootApplication注解的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • @SpringBootApplication注解说明(InsCode AI 创作助手)

    @SpringBootApplication 是 Spring Boot 中的一个关键注解,用于标识一个类是 Spring Boot 应用程序的主应用程序类。在这篇文章中,我们将详细解释 @SpringBootApplication 注解以及它在 Spring Boot 应用程序中的作用。 @SpringBootApplication 注解是 Spring Boot 中的一个复合注解,它包含了以下三个重

    2024年02月07日
    浏览(71)
  • idea的springboot项目的SpringBootApplication注解是红色的因为什么

    在 IntelliJ IDEA 中,当 Spring Boot 项目的 @SpringBootApplication 注解变为红色时,通常是因为以下原因之一: 缺少 Spring Boot 相关依赖: @SpringBootApplication 注解是 Spring Boot 项目的核心注解之一,如果您的项目缺少相关的 Spring Boot 依赖,IDEA 将无法正确解析该注解,从而导致变为红色。

    2024年02月07日
    浏览(32)
  • SpringBoot源码分析(1)--@SpringBootApplication注解使用和原理/SpringBoot的自动配置原理详解

    springboot原理索引 SpringBoot源码分析(1)–@SpringBootApplication注解使用和原理/SpringBoot的自动配置原理详解 SpringBoot源码分析(2)–SpringBoot启动源码(万字图文源码debug讲解springboot启动原理) 本文主要讲解@SpringBootApplication注解使用和原理。 源码基于spring-boot-2.2.13.RELEASE进行讲解 主要是

    2024年02月13日
    浏览(31)
  • @SpringBootApplication注解的理解——如何排除自动装配 & 分布式情况下如何自动加载 & nacos是怎么被发现的

    spring作为主流的 Java Web 开发的开源框架,是Java 世界最为成功的框架,持续不断深入认识spring框架是Java程序员不变的追求。 本篇博客介绍SpringBootApplicant注解的自动加载相关内容 其他相关的Spring博客文章列表如下: Spring基础(核心容器)——从配置文件到注解开发 创建对象

    2024年02月07日
    浏览(33)
  • 启动报错:SpringBootApplication扫描不到其他模块下的bean问题导致postman接口报404

    当启动类在3包下,但是我们的代码写在1包下的2中,代码没有生效,发接口报404,原因是启动类4没有扫描到1包下的代码。 启动报错:SpringBootApplication扫描不到其他模块下的bean问题导致postman接口报404 提示:关联两个包 需要在3包下的pom.xml中引入2这个包

    2024年02月14日
    浏览(33)
  • Spring Boot学习随笔-第一个SpringBoot项目快速启动(org.springframework.boot、@SpringBootApplication、application.yml)

    学习视频:【编程不良人】2021年SpringBoot最新最全教程 创建第一个Module 环境要求 jdk1.8+ maven3.2+ Spring Framework 5.x+ Tomcat 9.0+ IDEA 2021 自动保存刷新pom 在resources下添加application.yml文件后,即可启动springboot应用 由于tomcat内嵌在springboot里面了,所以我们在修改端口号等设置也在配置

    2024年02月05日
    浏览(44)
  • Spring Boot 启动注解分析

    虽然我们在日常开发中,Spring Boot 使用非常多,算是目前 Java 开发领域一个标配了,但是小伙伴们仔细想想自己的面试经历,和 Spring Boot 相关的面试题都有哪些?个人感觉应该是比较少的,Spring Boot 本质上还是曾经 SSM 那一套,只是通过各种 starter 简化了配置而已,其他都是

    2024年02月13日
    浏览(30)
  • 【spring源码系列-04】注解方式启动spring时refresh的前置工作

    Spring源码系列整体栏目 内容 链接地址 【一】spring源码整体概述 https://blog.csdn.net/zhenghuishengq/article/details/130940885 【二】通过refresh方法剖析IOC的整体流程 https://blog.csdn.net/zhenghuishengq/article/details/131003428 【三】xml配置文件启动spring时refresh的前置工作 https://blog.csdn.net/zhenghuishen

    2024年02月08日
    浏览(32)
  • Tomcat启动失败,启动子级时出错 IllegalStateException,因为我们有相同的WebServlet注解配置路径,有两个相同的上下文路径,所以会报错。

      这是一个关于Tomcat启动Web项目时出现异常的报错信息。报错信息中提到了一个IllegalStateException异常,这个异常通常是由于Tomcat在启动子级时出现了错误导致的。具体来说,这个异常可能是由于以下原因引起的: 应用程序的上下文路径已经存在于Tomcat中,但是Tomcat正在尝试将

    2024年04月12日
    浏览(47)
  • idea 提示Cannot resolve SpringBootApplication 是啥错

    Cannot resolve SpringBootApplication\\\" 这个错误提示通常出现在使用 IntelliJ IDEA 开发 Spring Boot 项目时,IDEA 无法解析 @SpringBootApplication 注解的情况。这种错误一般是由于项目配置问题或者依赖缺失导致的。 要解决这个问题,您可以尝试以下方法: 检查依赖: 确保您的项目已经正确添

    2024年02月08日
    浏览(37)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包