目录
springboot启动原理
springboot 2.4.0 启动源码分析
SpringBoot启动的基本配置
SpringBoot启动的配置主要有以下两个部分
添加依赖
最基本的springboot依赖只需要添加一个springboot启动器的依赖即可,如果是web服务则添加web的启动器
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.4.0</version> <relativePath/> </parent> <groupId>org.example</groupId> <artifactId>springboot.demo</artifactId> <version>1.0-SNAPSHOT</version> <dependencies> <!-- 如果不需要web服务则直接添加spring-boot-starter依赖即可不过我们一般都是需要web容器,所以直接添加spring-boot-starter-web依赖--> <!-- <dependency>--> <!-- <groupId>org.springframework.boot</groupId>--> <!-- <artifactId>spring-boot-starter</artifactId>--> <!-- </dependency>--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies> <properties> <maven.compiler.source>8</maven.compiler.source> <maven.compiler.target>8</maven.compiler.target> </properties> </project>
添加启动类注解
springboot启动的时候需要在启动类上面加上@SpringBootAppl