IDEA創(chuàng)建SpringBoot的maven項(xiàng)目的方法步驟
記錄IDEA編程工具創(chuàng)建SpringBoot的maven項(xiàng)目過(guò)程:
新建項(xiàng)目選擇maven項(xiàng)目及JDK,點(diǎn)擊下一步:
選擇好項(xiàng)目路徑,輸入項(xiàng)目名稱,點(diǎn)擊完成就可以啦:
創(chuàng)建完成效果:
新建項(xiàng)目需要引入springboot的依賴,這里選擇2.4.4版本。
完整pom文件如下:
<?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 http://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.4.4</version><relativePath/> <!-- lookup parent from repository --> </parent> <groupId>org.example</groupId> <artifactId>SpringBoot-Test</artifactId> <version>1.0-SNAPSHOT</version> <properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding><java.version>1.8</java.version> </properties> <dependencies><dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId></dependency><dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope></dependency> </dependencies> <build><plugins> <plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId> </plugin></plugins> </build></project>配置application.yml
配置文件中需配置端口號(hào)(默認(rèn)是80)和項(xiàng)目名稱,當(dāng)然不配置也可以正常啟動(dòng),只不過(guò)為了區(qū)別于其他項(xiàng)目,還是配置完比較好。
# 服務(wù)端口號(hào),默認(rèn)80server: port: 8866spring:# 服務(wù)名稱 application: name: springboot-test創(chuàng)建啟動(dòng)文件
在src/main/java目錄下創(chuàng)建com/springboot目錄,在springboot目錄下創(chuàng)建啟動(dòng)文件,命名為SpringBootTestApplication,添加main入口,配置@SpringBootApplication注解,聲明這是一個(gè)SpringBoot項(xiàng)目:
啟動(dòng)項(xiàng)目
右鍵啟動(dòng)項(xiàng)目文件,選擇運(yùn)行:
啟動(dòng)成功,控制臺(tái)顯示啟動(dòng)的端口號(hào)為我們?cè)O(shè)置的端口號(hào)。
測(cè)試接口訪問(wèn)
在com/springboot目錄下創(chuàng)建controller目錄,用來(lái)存放控制層文件,創(chuàng)建TestController類,添加@RestController注解,聲明這是控制層,定義測(cè)試接口方法demo,打印訪問(wèn)成功:
重新啟動(dòng)項(xiàng)目,利用Terminal訪問(wèn)http://localhost:8866/test/demo進(jìn)行測(cè)試
成功訪問(wèn)
你可能感興趣的內(nèi)容1、IDEA如何在一個(gè)項(xiàng)目空間下管理多個(gè)項(xiàng)目?
到此這篇關(guān)于IDEA創(chuàng)建SpringBoot的maven項(xiàng)目的方法步驟的文章就介紹到這了,更多相關(guān)SpringBoot創(chuàng)建maven項(xiàng)目?jī)?nèi)容請(qǐng)搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
1. asp(vbs)Rs.Open和Conn.Execute的詳解和區(qū)別及&H0001的說(shuō)明2. CSS hack用法案例詳解3. ASP 處理JSON數(shù)據(jù)的實(shí)現(xiàn)代碼4. PHP設(shè)計(jì)模式中工廠模式深入詳解5. 用css截取字符的幾種方法詳解(css排版隱藏溢出文本)6. asp中response.write("中文")或者js中文亂碼問(wèn)題7. ASP.NET MVC遍歷驗(yàn)證ModelState的錯(cuò)誤信息8. ThinkPHP5實(shí)現(xiàn)JWT Token認(rèn)證的過(guò)程(親測(cè)可用)9. ASP 信息提示函數(shù)并作返回或者轉(zhuǎn)向10. .Net Core和RabbitMQ限制循環(huán)消費(fèi)的方法
