詳解SpringBoot工程的三種搭建方式
SpringBoot的主要目的是簡(jiǎn)化配置文件,通過(guò)少量配置即可運(yùn)行Java程序,其強(qiáng)大的自動(dòng)配置功能幫助開(kāi)發(fā)者輕松實(shí)現(xiàn)配置裝配,通過(guò)引入SpringBoot的 starter 就能實(shí)現(xiàn)想要的功能,不需要額外的配置。
目前SpringBoot工程有三種搭建方式:
- 通過(guò)Spring Initializr創(chuàng)建
- 通過(guò)IDEA創(chuàng)建工程
- 手動(dòng)創(chuàng)建工程
官方生成工具
Spring團(tuán)隊(duì)提供一個(gè)非常方便的網(wǎng)頁(yè)用于生成SpringBoot工程,打開(kāi)瀏覽器進(jìn)入Spring Initializr:

工程生成參數(shù)列表:
- Project: 工程類型(支持Maven和Gradle構(gòu)建工具)
- Language:工程主要語(yǔ)言根據(jù)需要可選擇Java、Kotlin、Groovy
- SpringBoot:SpringBoot版本
- ProjectMatedata:有
Group和Artifact等配置 - Dependencies:工程依賴
參數(shù)設(shè)置完成后點(diǎn)擊 Generate 下載工程,完成后使用 IDEA 導(dǎo)入工程,打開(kāi)工程同步即可運(yùn)行。
IDEA創(chuàng)建工程
較新的 IDEA 版本都內(nèi)置創(chuàng)建SpringBoot工程插件,其創(chuàng)建原理也是使用的Spring Initializr來(lái)創(chuàng)建工程,創(chuàng)建流程下如:
- 打開(kāi)
IDEA開(kāi)發(fā)工具 - 選擇
file->new->project菜單 - 在新的對(duì)話框中選擇
Spring Initializr - 點(diǎn)擊
Next即可創(chuàng)建SpringBoot工程

最后添加 main 方法啟動(dòng)應(yīng)用程序:
@SpringBootApplication
@Slf4j
public class SpringEnvApplication {
public static void main(String[] args) {
ConfigurableApplicationContext context = SpringApplication.run(SpringEnvApplication.class, args);
}
}
手動(dòng)創(chuàng)建SpringBoot工程
除了以上兩種方式外,還可以通過(guò)手動(dòng)創(chuàng)建的方式創(chuàng)建SpringBoot工程,通過(guò) IDEA 創(chuàng)建一個(gè)空的 Maven 工程,然后指定SpringBoot的依賴就,基本流程如下:
- 打開(kāi)
IDEA開(kāi)發(fā)工具 - 選擇
file->new->project菜單 - 在新的對(duì)話框中選擇
Mavenn - 點(diǎn)擊
Next根據(jù)提示完成項(xiàng)目創(chuàng)建
工程創(chuàng)建完成后,打開(kāi) pom.xml 文件,設(shè)置 pom.xml 的parent配置:
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.2.0.RELEASE</version> </parent>
添加SpringBoot Maven 打包插件:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
添加 main 方法啟動(dòng)應(yīng)用程序:
@SpringBootApplication
@Slf4j
public class SpringEnvApplication {
public static void main(String[] args) {
ConfigurableApplicationContext context = SpringApplication.run(SpringEnvApplication.class, args);
}
}
完整 pom.xml 文件:
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.csbaic.arch</groupId>
<artifactId>spring-env</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>spring-env</name>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
設(shè)置parent和插件后,就可以使用SpringBoot創(chuàng)建應(yīng)用程序了。
- Maven搭建springboot項(xiàng)目的方法步驟
- SpringBoot多模塊項(xiàng)目框架搭建過(guò)程解析
- SpringBoot2整合activiti6環(huán)境搭建過(guò)程解析
- 詳解Springboot Oauth2 Server搭建Oauth2認(rèn)證服務(wù)
- springboot2.0和springcloud Finchley版項(xiàng)目搭建(包含eureka,gateWay,F(xiàn)reign,Hystrix)
- IDEA基于支付寶小程序搭建springboot項(xiàng)目的詳細(xì)步驟
- 使用Springboot搭建OAuth2.0 Server的方法示例
- SpringBoot快速搭建實(shí)現(xiàn)三步驟解析
相關(guān)文章
Spring Boot2配置服務(wù)器訪問(wèn)日志過(guò)程解析
這篇文章主要介紹了Spring Boot2配置服務(wù)器訪問(wèn)日志過(guò)程解析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2019-11-11
SpringBoot服務(wù)設(shè)置禁止server.point端口的使用
本文主要介紹了SpringBoot服務(wù)設(shè)置禁止server.point端口的使用,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2024-01-01
Java 異步線程監(jiān)聽(tīng)與結(jié)果回調(diào)及異常捕獲總結(jié)分析
異常是程序之中導(dǎo)致程序中斷的一種指令流,異常一旦出現(xiàn)并且沒(méi)有進(jìn)行合理處理的話,那么程序就將中斷執(zhí)行,這篇文章綜合介紹了異步線程監(jiān)聽(tīng)與結(jié)果回調(diào)及異常捕獲2021-11-11
基于request獲取訪問(wèn)者真實(shí)IP代碼示例
這篇文章主要介紹了基于request獲取訪問(wèn)者真實(shí)IP代碼示例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-10-10
JavaIO?BufferedReader和BufferedWriter使用及說(shuō)明
這篇文章主要介紹了JavaIO?BufferedReader和BufferedWriter使用及說(shuō)明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-12-12
使用mybatis框架連接mysql數(shù)據(jù)庫(kù)的超詳細(xì)步驟
MyBatis是目前java項(xiàng)目連接數(shù)據(jù)庫(kù)的最流行的orm框架了,下面這篇文章主要給大家介紹了關(guān)于使用mybatis框架連接mysql數(shù)據(jù)庫(kù)的超詳細(xì)步驟,文中通過(guò)實(shí)例代碼和圖文介紹的非常詳細(xì),需要的朋友可以參考下2023-04-04
SpringCloud分布式項(xiàng)目下feign的使用示例詳解
這篇文章主要介紹了SpringCloud分布式項(xiàng)目下feign的使用,本文通過(guò)示例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2023-07-07
永中文檔在線轉(zhuǎn)換服務(wù)Swagger調(diào)用說(shuō)明
這篇文章主要為大家介紹了永中文檔在線轉(zhuǎn)換服務(wù)Swagger調(diào)用說(shuō)明,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-06-06

