SpringBoot工程的三種搭建方式分別是什么,針對這個問題,這篇文章詳細介紹了相對應的分析和解答,希望可以幫助更多想解決這個問題的小伙伴找到更簡單易行的方法。

SpringBoot的主要目的是簡化配置文件,通過少量配置即可運行Java程序,其強大的自動配置功能幫助開發(fā)者輕松實現(xiàn)配置裝配,通過引入SpringBoot的starter 就能實現(xiàn)想要的功能,不需要額外的配置。
目前SpringBoot工程有三種搭建方式:
通過Spring Initializr創(chuàng)建 通過IDEA創(chuàng)建工程 手動創(chuàng)建工程
官方生成工具
Spring團隊提供一個非常方便的網頁用于生成SpringBoot工程,打開瀏覽器進入Spring Initializr:
工程生成參數列表:
Project: 工程類型(支持Maven和Gradle構建工具) Language:工程主要語言根據需要可選擇Java、Kotlin、Groovy SpringBoot:SpringBoot版本 ProjectMatedata:有Group 和Artifact 等配置 Dependencies:工程依賴
參數設置完成后點擊Generate 下載工程,完成后使用IDEA 導入工程,打開工程同步即可運行。
IDEA創(chuàng)建工程
較新的IDEA 版本都內置創(chuàng)建SpringBoot工程插件,其創(chuàng)建原理也是使用的Spring Initializr來創(chuàng)建工程,創(chuàng)建流程下如:
打開IDEA 開發(fā)工具 選擇file ->new ->project 菜單 在新的對話框中選擇Spring Initializr 點擊Next 即可創(chuàng)建SpringBoot工程
最后添加main 方法啟動應用程序:
@SpringBootApplication@Slf4jpublic class SpringEnvApplication { public static void main(String[] args) { ConfigurableApplicationContext context = SpringApplication.run(SpringEnvApplication.class, args); }}
手動創(chuàng)建SpringBoot工程
除了以上兩種方式外,還可以通過手動創(chuàng)建的方式創(chuàng)建SpringBoot工程,通過IDEA 創(chuàng)建一個空的Maven 工程,然后指定SpringBoot的依賴就,基本流程如下:
打開IDEA 開發(fā)工具 選擇file ->new ->project 菜單 在新的對話框中選擇Mavenn 點擊Next 根據提示完成項目創(chuàng)建
工程創(chuàng)建完成后,打開pom.xml 文件,設置pom.xml 的parent配置:
<parent> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId> <version>2.2.0.RELEASE</version></parent>
添加SpringBootMaven 打包插件:
<build> <plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin> </plugins></build>
添加main 方法啟動應用程序:
@SpringBootApplication@Slf4jpublic 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>
設置parent和插件后,就可以使用SpringBoot創(chuàng)建應用程序了。
關于SpringBoot工程的三種搭建方式分別是什么問題的解答就分享到這里了,希望以上內容可以對大家有一定的幫助,如果你還有很多疑惑沒有解開,可以關注創(chuàng)新互聯(lián)行業(yè)資訊頻道了解更多相關知識。
網頁標題:SpringBoot工程的三種搭建方式分別是什么-創(chuàng)新互聯(lián)
新聞來源:http://www.chinadenli.net/article4/pdsie.html
成都網站建設公司_創(chuàng)新互聯(lián),為您提供服務器托管、小程序開發(fā)、關鍵詞優(yōu)化、ChatGPT、App開發(fā)、網頁設計公司
聲明:本網站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內容