maven創建SpringBoot項目

使用maven創建SpringBoot項目有幾種方式,使用spring-boot-starter-parent 和使用spring-boot-dependencies ,同理springcloud 項目也可以使用兩種方式創建,推薦使用dependencyManagement,使用IDEA直接創建也是可以的!

一、使用spring-boot-starter-parent

<!-- SpringBoot應用的打包插件 -->
<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

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

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
</dependencies>

使用spring-boot-starter-parent 雖然方便,但是很多開發場景下需要用到自己公司的parent,如果這個時候還想進行項目依賴版本的統一管理,就需要使用spring-boot-dependencies這種方式來實現了!

二、使用spring-boot-dependencies ,推薦使用此種方式

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-dependencies</artifactId>
            <version>2.0.4.RELEASE</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
    </plugins>
</build>

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

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
</dependencies>

編寫寫一個主類和一個Controller:

@SpringBootApplication
public class MainApplication {
    public static void main(String[] args) {
        SpringApplication.run(MainApplication.class, args);
    }
}

//----------------------------------------------------------------

@RestController
@ResponseBody
public class HelloController {

    @RequestMapping("/hello")
    public String hello(){
        return "Hello SpringBoot Application";
    }
}

在這裏插入圖片描述

三、最省力的方式創建SpringBoot應用

在這裏插入圖片描述

Tip:如何定製banner?

http://www.network-science.de/ascii/ 在這個網站裏定製你的啓動文字,然後新建一個banner.txt放在資源文件夾即可:
在這裏插入圖片描述
在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章