SpringBoot工程的三種搭建方式分別是什么,針對(duì)這個(gè)問題,這篇文章詳細(xì)介紹了相對(duì)應(yīng)的分析和解答,希望可以幫助更多想解決這個(gè)問題的小伙伴找到更簡(jiǎn)單易行的方法。
為太白等地區(qū)用戶提供了全套網(wǎng)頁設(shè)計(jì)制作服務(wù),及太白網(wǎng)站建設(shè)行業(yè)解決方案。主營業(yè)務(wù)為成都網(wǎng)站設(shè)計(jì)、成都做網(wǎng)站、太白網(wǎng)站設(shè)計(jì),以傳統(tǒng)方式定制建設(shè)網(wǎng)站,并提供域名空間備案等一條龍服務(wù),秉承以專業(yè)、用心的態(tài)度為用戶提供真誠的服務(wù)。我們深信只要達(dá)到每一位用戶的要求,就會(huì)得到認(rèn)可,從而選擇與我們長(zhǎng)期合作。這樣,我們也可以走得更遠(yuǎn)!
SpringBoot的主要目的是簡(jiǎn)化配置文件,通過少量配置即可運(yùn)行Java程序,其強(qiáng)大的自動(dòng)配置功能幫助開發(fā)者輕松實(shí)現(xiàn)配置裝配,通過引入SpringBoot的 starter
就能實(shí)現(xiàn)想要的功能,不需要額外的配置。
目前SpringBoot工程有三種搭建方式:
通過Spring Initializr創(chuàng)建 通過IDEA創(chuàng)建工程 手動(dòng)創(chuàng)建工程
官方生成工具
Spring團(tuán)隊(duì)提供一個(gè)非常方便的網(wǎng)頁用于生成SpringBoot工程,打開瀏覽器進(jìn)入Spring Initializr:
工程生成參數(shù)列表:
Project: 工程類型(支持Maven和Gradle構(gòu)建工具) Language:工程主要語言根據(jù)需要可選擇Java、Kotlin、Groovy SpringBoot:SpringBoot版本 ProjectMatedata:有 Group
和 Artifact
等配置 Dependencies:工程依賴
參數(shù)設(shè)置完成后點(diǎn)擊 Generate
下載工程,完成后使用 IDEA
導(dǎo)入工程,打開工程同步即可運(yùn)行。
IDEA創(chuàng)建工程
較新的 IDEA
版本都內(nèi)置創(chuàng)建SpringBoot工程插件,其創(chuàng)建原理也是使用的Spring Initializr來創(chuàng)建工程,創(chuàng)建流程下如:
打開 IDEA
開發(fā)工具 選擇 file
-> new
-> project
菜單 在新的對(duì)話框中選擇 Spring Initializr
點(diǎn)擊 Next
即可創(chuàng)建SpringBoot工程
最后添加 main
方法啟動(dòng)應(yīng)用程序:
@SpringBootApplication@Slf4jpublic class SpringEnvApplication { public static void main(String[] args) { ConfigurableApplicationContext context = SpringApplication.run(SpringEnvApplication.class, args); }}
手動(dòng)創(chuàng)建SpringBoot工程
除了以上兩種方式外,還可以通過手動(dòng)創(chuàng)建的方式創(chuàng)建SpringBoot工程,通過 IDEA
創(chuàng)建一個(gè)空的 Maven
工程,然后指定SpringBoot的依賴就,基本流程如下:
打開 IDEA
開發(fā)工具 選擇 file
-> new
-> project
菜單 在新的對(duì)話框中選擇 Mavenn
點(diǎn)擊 Next
根據(jù)提示完成項(xiàng)目創(chuàng)建
工程創(chuàng)建完成后,打開 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@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>
設(shè)置parent和插件后,就可以使用SpringBoot創(chuàng)建應(yīng)用程序了。
關(guān)于SpringBoot工程的三種搭建方式分別是什么問題的解答就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,如果你還有很多疑惑沒有解開,可以關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道了解更多相關(guān)知識(shí)。
網(wǎng)頁題目:SpringBoot工程的三種搭建方式分別是什么
當(dāng)前網(wǎng)址:http://aaarwkj.com/article22/jeigcc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供靜態(tài)網(wǎng)站、微信公眾號(hào)、網(wǎng)頁設(shè)計(jì)公司、Google、做網(wǎng)站、網(wǎng)站導(dǎo)航
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)