在华丽悦耳的语言,也不及代码的真切。

无论,我们是通过IDEA工具创建的SpringBoot项目,还是通过Spring官网生成的项目,再还是通过手动搭建的SpringBoot项目。都有一个共同的特点,那就是它们是一个Maven工程。这样的工程好处,我就在这里不一一道来了。

接下来,让我们看看SpringBoot的三种启动方式,你必须了解的。

一、通过IDEA工具运行Application这个类的main方法

我们先写一个HelloController.java类,练练手。

package com.xbmu;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by bitaotao on 2018-04-05.
 */
@RestController
public class HelloController {
    @RequestMapping(value = "/hello",method = RequestMethod.GET)
    public String sayHello(){
        return "Hello,SpringBoot.";
    }
}

<?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.xbmu</groupId>
   <artifactId>girl</artifactId>
   <version>0.0.1-SNAPSHOT</version>
   <packaging>jar</packaging>

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

   <parent>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-parent</artifactId>
      <version>1.5.10.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>

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

spring boot 启动管理 spring boot如何启动_SpringBoot

二、在SpringBoot的应用的根目录下运行mvn spring-boot:run

spring boot 启动管理 spring boot如何启动_SpringBoot_02


 



spring boot 启动管理 spring boot如何启动_SpringBoot_03

启动后的窗口关闭了,就表示已经关闭了启动的SpringBoot。

三、使用mvn install 生成jar后运行

spring boot 启动管理 spring boot如何启动_xml_04

spring boot 启动管理 spring boot如何启动_SpringBoot_05

spring boot 启动管理 spring boot如何启动_maven_06