Mapleyang

导航

 

新建好一个springboot项目

  • 在pom.xml中加入web依赖

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
  • 在pom.xml中加入热部署,可以在修改代码是不用重启就可以运行,Ctrl+F9启动热部署

<!--启动热部署-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
        </dependency>

 

运行原理探究

我们之前写的HelloSpringBoot,到底是怎么运行的呢,Maven项目,我们一般从pom.xml文件探究起;

父依赖

pom.xml:

  • spring-boot-dependencies:核心依赖在父工程中!
  • 我们在写或者引入一些Springboot依赖的时候,不需要指定版本,就因为有这些版本仓库

 

 

主程序

  默认的主启动类

  

package com.maple.spring01hellowprld;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

//@SpringBootApplication 来标注一个主程序类
//说明这是一个Spring Boot应用
@SpringBootApplication
public class Spring01HellowprldApplication {
    public static void main(String[] args) {
        //以为是启动了一个方法,没想到启动了一个服务
        SpringApplication.run(Spring01HellowprldApplication.class, args);
    }

}

 

 

SpringApplication

  • 推断应用的类型是普通的项目还是Web项目
  • 查找并加载所有可用初始化器 , 设置到initializers属性中
  • 找出所有的应用程序监听器,设置到listeners属性中
  • 推断并设置main方法的定义类,找到运行的主类

 

posted on 2022-08-08 21:51  折木~  阅读(22)  评论(0)    收藏  举报