SpringBoot(一)-入门介绍

8 篇文章 0 订阅
6 篇文章 0 订阅
本文介绍了如何使用Spring Boot的父依赖、启动器组件,以及@SpringBootApplication注解的配置、自动配置和扫描功能。详细解读了@SpringBootConfiguration、@EnableAutoConfiguration和@ComponentScan的作用,帮助理解Spring Boot快速应用开发过程。
摘要由CSDN通过智能技术生成

一、父依赖

 	<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.5.1</version>
    </parent>

父依赖包装了dependencies:启动boot的所有依赖版本控制

 <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-dependencies</artifactId>
    <version>2.5.1</version>
  </parent>

在这里插入图片描述

二、启动器

 		<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

web启动器导入了所有与web场景相关的依赖组件

如下所示

 <dependencies>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter</artifactId>
      <version>2.5.1</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-json</artifactId>
      <version>2.5.1</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-tomcat</artifactId>
      <version>2.5.1</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-web</artifactId>
      <version>5.3.8</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-webmvc</artifactId>
      <version>5.3.8</version>
      <scope>compile</scope>
    </dependency>
  </dependencies>

在Using Spring Boot文档里面包含了各个场景所使用的启动器

三、主程序注解@SpringBootApplication

//声明是一个boot应用,会扫描当前类所在包里的所有组件
@SpringBootApplication

@SpringBootApplication注解所在MainApplication类在chime包,chime包里的所有组件将被扫描
chime外的HelloController不会被扫进去
在这里插入图片描述

@SpringBootApplication主要由配置注解和开启自动配置以及扫描注解组成

@SpringBootConfiguration//配置类
@EnableAutoConfiguration//自动配置
@ComponentScan//扫描

1、@SpringBootConfiguration

@SpringBootConfiguration
实际上就是一个@Configuration
@Configuration实际上就是一个@Component

2、@EnableAutoConfiguration

@AutoConfigurationPackage//自动配置包
@Import({AutoConfigurationImportSelector.class})//导入指定配置类

自动配置类可以根据spring.factories找到所需的自动配置类,都是已经封装好的,代替了Spring的手动配置
在这里插入图片描述

3、@ComponentScan

扫描当前所在包的所有组件

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值