SpringBoot笔记

SpringBoot优点

  • Create stand-alone Spring applications
    • 创建独立Spring应用
  • Embed Tomcat, Jetty or Undertow directly (no need to deploy WAR files)
    • 内嵌web服务器
  • Provide opinionated 'starter' dependencies to simplify your build configuration
    • 自动starter依赖,简化构建配置
  • Automatically configure Spring and 3rd party libraries whenever possible
    • 自动配置Spring以及第三方功能
  • Provide production-ready features such as metrics, health checks, and externalized configuration
    • 提供生产级别的监控、健康检查及外部化配置
  • Absolutely no code generation and no requirement for XML configuration
    • 无代码生成、无需编写XML

 

SpringBoot是整合Spring技术栈的一站式框架

SpringBoot是简化Spring技术栈的快速开发脚手架

 

2.2、SpringBoot缺点

  • 人称版本帝,迭代快,需要时刻关注变化
  • 封装太深,内部原理复杂,不容易精通

查看版本新特性;

https://github.com/spring-projects/spring-boot/wiki#release-notes

02、SpringBoot2入门

1、系统要求

  • Java 8 & 兼容java14 .
  • Maven 3.3+
  • idea 2019.1.2
<mirrors>

      <mirror>

        <id>nexus-aliyun</id>

        <mirrorOf>central</mirrorOf>

        <name>Nexus aliyun</name>

        <url>http://maven.aliyun.com/nexus/content/groups/public</url>

      </mirror>

  </mirrors>

 

  <profiles>

         <profile>

              <id>jdk-1.8</id>

              <activation>

                <activeByDefault>true</activeByDefault>

                <jdk>1.8</jdk>

              </activation>

              <properties>

                <maven.compiler.source>1.8</maven.compiler.source>

                <maven.compiler.target>1.8</maven.compiler.target>

                <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>

              </properties>

         </profile>

  </profiles>

03、了解自动配置原理

1、SpringBoot特点

 

1.1、依赖管理

  • 父项目做依赖管理
  • 依赖管理    
    
    <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>
    
    
    几乎声明了所有开发中常用的依赖的版本号,自动版本仲裁机制

    开发导入starter场景启动器

  • 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: 第三方为我们提供的简化开发的场景启动器。
    
    5、所有场景启动器最底层的依赖
    
    <dependency>
    
      <groupId>org.springframework.boot</groupId>
    
      <artifactId>spring-boot-starter</artifactId>
    
      <version>2.3.4.RELEASE</version>
    
      <scope>compile</scope>
    
    </dependency>

    无需关注版本号,自动版本仲裁

  • 1、引入依赖默认都可以不写版本
    
    2、引入非版本仲裁的jar,要写版本号。

    可以修改默认版本号

  • 1、查看spring-boot-dependencies里面规定当前依赖的版本 用的 key。
    
    2、在当前项目里面重写配置
    
        <properties>
    
            <mysql.version>5.1.43</mysql.version>
    
        </properties>

    1.2、自动配置

    • 自动配好Tomcat
      • 引入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
        • 引入SpringMVC全套组件
        • 自动配好SpringMVC常用组件(功能)
      • 自动配好Web常见功能,如:字符编码问题
        • SpringBoot帮我们配置好了所有web开发的常见场景
      • 默认的包结构
        • 主程序所在包及其下面的所有子包里面的组件都会被默认扫描进来
        • 无需以前的包扫描配置
        • 想要改变扫描路径,@SpringBootApplication(scanBasePackages="com.atguigu")
          • 或者@ComponentScan 指定扫描路径
          • @SpringBootApplication
            
            等同于
            
            @SpringBootConfiguration
            
            @EnableAutoConfiguration
            
            @ComponentScan("com.atguigu.boot")
posted @ 2021-03-11 15:09  幸福在靠近  阅读(47)  评论(0编辑  收藏  举报