環(huán)境準備:
開發(fā)工具IDE:IntelliJ IDEA 2022.2.4 (Ultimate Edition)
開發(fā)環(huán)境JDK:Oracle OpenJDK Version 1.8.0_162
構(gòu)建工具MAVEN: Maven 3.6.3
一、創(chuàng)建Spring boot 項目
(1)創(chuàng)建spring initializr工程
通過IntelliJ IDEA工具創(chuàng)建工程時,通過file->new->project后,在彈出的界面中選擇spring initializr選項(社區(qū)版無此選項)。然后去勾選相關(guān)依賴。
如果默認網(wǎng)址不能訪問,可以換國內(nèi)的網(wǎng)址,如:阿里云網(wǎng)址 https://start.aliyun.com/
(2)勾選需要引用的jar包
Spring Boot 版本默認是最新的版本,可以點擊下拉列表選取,也可通過pom文件中修改Spring boot的版本號來引入對應(yīng)的Spring boot版本。
此處可勾選需要的jar包,如果不知道自己需要引入那些jar,也可不選擇,后續(xù)通過在pom文件中填寫jar的坐標,也可導(dǎo)入jar,方便快捷
(3)項目創(chuàng)建完畢
本項目采用maven來管理項目jar包和構(gòu)建項目,也可以采用gradle來替代maven,具體怎么做大家可以自行研究。
需要的jar坐標,可以去maven公共倉庫搜索,地址:
https://mvnrepository.com/
(4) 啟動項目
項目運行只需要啟動帶有main方法的類即可,Spring boot 內(nèi)置三種servlet容器 tomcat,jetty 和 undertow,默認Tomcat容器,不用配置servlet容器
到此為止一個Spring boot項目搭建完畢。
-
切換servlet容器
-
切換Jeety
<dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> </exclusion> </exclusions> </dependency> <!-- Jetty適合長連接應(yīng)用,聊天類的長連接 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jetty</artifactId> </dependency> </dependencies>
-
切換Undertow
<dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> </exclusion> </exclusions> </dependency> <!-- undertow不支持jsp --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-undertow</artifactId> </dependency> </dependencies>
-
(5)通過官網(wǎng)創(chuàng)建項目
如果你的IntelliJ IDEA是社區(qū)版,則可以通過官網(wǎng)
https://start.spring.io/
生成項目工程,導(dǎo)出后再導(dǎo)入到IntelliJ IDEA。其創(chuàng)建項目跟IntelliJ IDEA基本類似.
二、Spring boot項目配置文件設(shè)置
注:Spring boot 支持.properties和.yaml格式的配置文件,.yaml格式文件更趨向json格式,看起來比較方便,本例采用.yaml格式配置文件。
文章來源:http://www.zghlxwxcb.cn/news/detail-768871.html
到這里,我們第一個spring boot 項目就創(chuàng)建完畢。
關(guān)注我,跟著我每天實戰(zhàn)項目。文章來源地址http://www.zghlxwxcb.cn/news/detail-768871.html
到了這里,關(guān)于【環(huán)境搭建】使用IDEA創(chuàng)建快速搭建SpringBoot項目詳細步驟的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!