springboot学习笔记_02_依赖管理&&自动配置

依赖管理&&自动配置

依赖管理

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.3.4.RELEASE</version>
</parent>
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-dependencies</artifactId>
    <version>2.3.4.RELEASE</version>
</parent>
  • 父项目
    • 包含众多jar包的版本号
    • 在引入jar包时可以不需要版本号(自动版本仲裁机制)
    • 也可自定义版本号(就近原则)

场景启动器

  • spring-boot-starter-*
    • *就某种场景
    • 引入starter,本场景常规依赖依自动引入
    • 所有场景
      • https://docs.spring.io/spring-boot/docs/current/reference/html/using-spring-boot.html#using-boot-starter
    • 第三方场景启动器
      • *-spring-boot-starter
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter</artifactId>
    <version>2.3.4.RELEASE</version>
    <scope>compile</scope>
</dependency>

自动配置

  • tomcat
    • tomcat依赖
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-tomcat</artifactId>
    <version>2.3.4.RELEASE</version>
    <scope>compile</scope>
</dependency>
  • springmvc
  • 默认包扫描规则
    • 主程序所在包及其子包会被默认扫描
    • 也可手动扫描
      • @SpringBootApplication(scanBasePackages=“xx.xx”)
      • @ComponentScan(“xx.xx”)
  • 其他默认配置
    • 配置文件的值会绑定每个类,在容器中创建对象
    • 按需加载
    • 自动配置类
      • spring-boot-autoconfigure
@SpringBootApplication

等同于

@SpringBootConfiguration
@EnableAutoConfiguration
@ComponentScan("xx.xx")
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值