Java课题笔记~ SpringBoot概述

问题导入

学习了SpringBoot入门案例之后,感觉对比SpringMVC哪一个更加方便简洁?

  • SpringBoot是由Pivotal团队提供的全新框架,其设计目的是用来简化Spring应用的初始搭建以及开发过程

  • Spring程序缺点

    • 配置繁琐

    • 依赖设置繁琐

  • SpringBoot程序优点

    • 自动配置

    • 起步依赖(简化依赖配置)

    • 辅助功能(内置服务器,……)

2.1 起步依赖

  • starter

    • SpringBoot中常见项目名称,定义了当前项目使用的所有项目坐标,以达到减少依赖配置的目的



    4.0.0
    
        org.springframework.boot
        spring-boot-starter-parent
        2.5.0
    
    com.itheima
    springboot-01-quickstart
    0.0.1-SNAPSHOT
    
        
            org.springframework.boot
            spring-boot-starter-web
        
    

    4.0.0
    org.springframework.boot
    spring-boot-dependencies
    2.5.0
    pom
    
        4.0.1        
        ...
    

parent

  • 所有SpringBoot项目要继承的项目,定义了若干个坐标版本号(依赖管理,而非依赖),以达到减少依赖冲突的目的

  • spring-boot-starter-parent(2.5.0)与 spring-boot-starter-parent(2.4.6)共计57处坐标版本不同



    4.0.0
    
        org.springframework.boot
        spring-boot-dependencies
        2.5.0
    
    spring-boot-starter-parent
    pom    
    ...

实际开发

  • 使用任意坐标时,仅书写GAV中的G和A,V由SpringBoot提供

  • 如发生坐标错误,再指定version(要小心版本冲突)


    junit
    junit
    ${junit.version}


    javax.servlet
    javax.servlet-api
    ${servlet-api.version}


    
        org.springframework.boot
        spring-boot-starter-parent
        2.5.0
    
    
        
            org.springframework.boot
            spring-boot-starter-web
        
        
            org.springframework.boot
            spring-boot-starter-test
            test
        
    

2.2 辅助功能

  • SpringBoot程序启动

@SpringBootApplication
public class Springboot01QuickstartApplication {
    public static void main(String[] args) {
        SpringApplication.run(Springboot01QuickstartApplication.class, args);
    }
}
  • SpringBoot在创建项目时,采用jar的打包方式

  • SpringBoot的引导类是项目的入口,运行main方法就可以启动项目

  • 使用maven依赖管理变更起步依赖项

  • Jetty比Tomcat更轻量级,可扩展性更强(相较于Tomcat),谷歌应用引擎(GAE)已经全面切换为Jetty


    
        org.springframework.boot
        spring-boot-starter-web
        
        
            
                org.springframework.boot
                spring-boot-starter-tomcat
            
        
    
    
    
        org.springframework.boot
        spring-boot-starter-jetty
    

你可能感兴趣的:(Java,java,spring,boot,笔记)