SpringBoot进阶(一):再回首SpringBoot maven 项目的三种启动方式

227 阅读1分钟

注:引入的是 SpringBoot2.0.3.RELEASE 的版本父项目

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.3.RELEASE</version>
</parent>

第一种:

通过启动类:使用@SpringBootApplication注解
在这里插入图片描述

第二种:通过pom.xml中加入插件启动 加入插件之后右键项目 选中RunAs --> Maven bulid... 输入 spring -boot:run 单击Run就可以了

<plugins>
         <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <!-- maven的jdk编译版本插件,这里因为父项目是2.0.0版本,如果是1.5.4版本不需要导入jdk -->
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
      </plugins>

在这里插入图片描述

第三种: 在当前项目的根目录,也就是pom.xml文件所在的位置
在这里插入图片描述

按住shift键同时 右键鼠标 会出现 在此处打开 powerShell 然后单击 进入界面 输入 mvn spring-boot:run 就会出现如下界面。当前界面是在下载pom文件依赖的jar包,下载完成之后就可以正常访问。
在这里插入图片描述
在这里插入图片描述