SpringBoot(二):SpringBoot启动

· pom.xml中父级依赖了解
· pom.xml中启动依赖配置项
· 应用启动入口分析

1.pom.xml中父级依赖了解


        org.springframework.boot
        spring-boot-starter-parent
        2.2.5.RELEASE
         
    

这块配置时SpringBoot的父级依赖。
SpringBoot官网解释:

Spring Boot dependencies use the org.springframework.boot groupId. Typically, your Maven POM file inherits from the spring-boot-starter-parent project and declares dependencies to one or more “Starters”. Spring Boot also provides an optional Maven plugin to create executable jars.

spring-boot-starter-parent:可以看出,Maven POM文件继承自父项目。使用它之后,可以省略包依赖的version标签,因为在其中已经提供了一些包依赖的版本。可以在~/.m2/repository/org/springframework/boot/spring-boot-dependencies/2.2.5.RELEASE/spring-boot-dependencies-2.2.5.RELEASE.pom中查看


    5.15.11
    2.7.7
    1.9.78
    2.10.1
    1.9.5
    3.13.2
    4.0.6
    4.0.2
    2.1.4
    3.0.0
    1.10.8
    2.8.1
    3.7.2
    1.5.1
    1.13
    2.7.0
    3.9
    1.6

如果不想要使用默认版本,可以通过覆盖自己项目中的属性来覆盖各个依赖项。
在pom.xml的中添加想用的版本号即可修改

2.pom.xml中启动依赖配置项

pom.xml-Diagrams-Show Dependencies打开可以看到


image.png
                                         
    org.springframework.boot      
    spring-boot-starter-web 
                                        

这里可以看到spring-boot-starter-web包含了内置的tomcat,点击查看:

image.png

可以看出,Spring Boot降低了项目依赖的复杂性,更加便捷。

Maven插件,可以将项目打包成一个可执行的JAR,可以通过执行Java -jar方式运行程序。
                                                      
                                                    
                                                     
            org.springframework.boot      
            spring-boot-maven-plugin
                                                    
                                                   
                                                     

3.应用启动入口分析

我们就是通过运行这个main()方法启动程序。

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class HelloWorldApplication {

    public static void main(String[] args) {
        SpringApplication.run(HelloWorldApplication.class, args);
    }

}
  • 1.@SpringBootApplication:是SpringBoot的核心注解,可以启动自动配置。
  • 2.mian:就是Java应用的main方法,作为项目的启动入口。

你可能感兴趣的:(SpringBoot(二):SpringBoot启动)