SpringBoot三种启动方式

SpringBoot为Gradle和Maven提供了构建插件,以便辅助构建SpringBoot项目,如果选用Maven来构建应用程序,Initializr会替你生成一个pom.xml文件,其中使用了SpringBoot的Maven插件,

<?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>

    <groupId>com.ge</groupId>
    <artifactId>thesis</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>thesis</name>
    <description>Demo project for Spring Boot</description>

<!--从Spring-boot-starter-parent 继承版本号-->
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.4.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

<!--起步依赖-->
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <!--thymeleaf依赖-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>


</project>

通过Maven启动方法:spring-boot:run

当通过Gradle启动项目时道理是相同的,第三种方法 通过IDE启动,这里是IDEA举例

SpringBoot三种启动方式

这里的ThesisApplication是整个项目的启动类,

SpringBoot三种启动方式

点击图中的绿色图标即可启动该项目,

SpringBoot三种启动方式

或者点击图示处按钮,从左到右分别表示以run模式运行项目,以debug模式运行项目。