zoukankan      html  css  js  c++  java
  • 03.SpringBoot自动配置

    SpringBoot依赖管理

    利用父项目做依赖管理

    把一些常规的都放在spring-boot-starter-parent中封装好,里面声明了非常多的依赖

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

    只要引入starter,这个场景的所有常规需要的依赖我们都自动引入

    引入依赖默认都可以不写版本,但如果引入里面没有的jar,要写版本号,在当前项目里面重写配置

     <properties>
            <mysql.version>5.1.43</mysql.version>
        </properties>
    

    1、见到很多 spring-boot-starter-* : *就是某种场景

    2、只要引入starter,这个场景的所有常规需要的依赖我们都自动引入 3、

    SpringBoot所有支持的场景 https://docs.spring.io/spring-boot/docs/current/reference/html/using-spring-boot.html#using-boot-starter

    4、见到的 *-spring-boot-starter: 第三方为我们提供的简化开发的场景启动器。

    自动配置

    Web开发场景

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

    1.自动配置组件

    这里面配置了Tomcat、Spring、SpringMVC常用组件等等

    image-20210726205611128

    2.自动配置包结构

    在主程序以及下面所有的包都会被扫描进来

    如果想扫描主程序以外的包

    @SpringBootApplication(scanBasePackages = "com.ylc")
    

    或者ComponentScan来扫描

    @SpringBootApplication
    等同于
    @SpringBootConfiguration
    @EnableAutoConfiguration
    @ComponentScan("com.ylc")
    

    配置文件的值都会映射并且绑定到每个类中,容器中也有创建对象,例如之前的端口号

    image-20210726211303521

    有非常多的Strater场景,引入相关场景才会自动配置

    SpringBoot所有的自动配置功能都在 spring-boot-autoconfigure 包里面

  • 相关阅读:
    电脑桌面图标不显示图案变成白色图标该怎么办?
    行动上的巨人养成指南
    荣耀MagicBook Pro 2020款对比2019款做了哪些升级
    P8 function template ,函数模板
    MATLAB中imfill()函数
    MagicBook Pro 2020锐龙版
    P7. class template, 类模板,模板类
    6. namespace经验谈
    macbook pro2020参数
    MATLAB取整
  • 原文地址:https://www.cnblogs.com/cg-ww/p/15126708.html
Copyright © 2011-2022 走看看