如何通過幾個簡單的步驟在 IntelliJ IDEA 中創建第一個 Spring Boot HelloWorld 應用程序?
已發表: 2020-08-18讀者好——在本教程中,我們將介紹如何創建第一個非常簡單的 Hello World Spring Boot 應用程序的步驟列表,只需單擊幾下。
以前我寫過一篇關於如何在 Eclipse 中創建你的第一個 Spring Boot 應用程序的文章。 如果您想在 Eclipse IDE 中創建它,請看一下。
Spring Boot 應用程序的使用在過去幾年中增加了很多,因為在沒有 Apache Tomcat 和任何其他應用程序服務器的情況下運行應用程序非常簡單。
在下一個教程中,我們將創建一個簡單的 Spring Boot Web 應用程序,它偵聽端口 8081。
讓我們開始吧。
第1步。
- 打開 IntelliJ IDEA
- 點擊文件
- 點擊新建
- 點擊項目
第2步。
- IntelliJ IDEA - 使用
Spring Initializr
創建 Spring Boot 應用程序 - 點擊下一步
步驟 3。
- 提供項目詳細信息如下
- 組:
com.crunchify
- 神器:springboot
- 包:
com.crunchify.springboot
- Java 版本:13 或 14(您安裝的 JDK 二進製文件)
- 點擊下一步
第四步。
- 為您的 Spring Boot 應用程序選擇所有依賴項
- 我沒有為此項目選擇任何依賴項
- 點擊下一步
步驟 5。
- 這將在您的 IntelliJ IDEA 中創建新的 Spring Boot 應用程序。
- 打開文件:SrpingBootApplication.java
- 修改它以打印一些信息消息
將以下內容複製並粘貼到其中。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
package com . crunchify . springboot ; import org . springframework . boot . SpringApplication ; import org . springframework . boot . autoconfigure . SpringBootApplication ; /** * @author Crunchify.com * 1st Spring Hello World Application in Intellij IDEA by Crunchify.com * Version: 1.0 */ @ SpringBootApplication public class SpringbootApplication { public static void main ( String [ ] args ) { SpringApplication . run ( SpringbootApplication . class , args ) ; System . out . println ( "\n Hello. This is 1st Spring Hello World Application in Intellij IDEA by Crunchify.com" ) ; } } |
步驟 6。 建立一個項目
- 從左側面板右鍵單擊項目springboot
- 單擊構建模塊“springboot”
您應該看到如下成功構建消息。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
Clearing build system data . . . Executing pre - compile tasks . . . Loading Ant Configuration . . . Running Ant Tasks . . . Cleaning output directories . . . Running 'before' tasks Checking sources Copying resources . . . [ springboot ] Parsing java . . . [ springboot ] Writing classes . . . [ springboot ] Updating dependency information . . . [ springboot ] Adding @ NotNull assertions . . . [ springboot ] Adding pattern assertions . . . [ springboot ] Parsing java . . . [ tests of springboot ] Writing classes . . . [ tests of springboot ] Updating dependency information . . . [ tests of springboot ] Adding @ NotNull assertions . . . [ tests of springboot ] Adding pattern assertions . . . [ tests of springboot ] Running 'after' tasks javac 14.0.2 was used to compile java sources Finished , saving caches . . . Executing post - compile tasks . . . Loading Ant Configuration . . . Running Ant Tasks . . . Synchronizing output directories . . . 8 / 17 / 20 , 12 : 11 PM - Build completed successfully in 2 s 236 ms |
步驟 7。 運行 Java 程序
- 右鍵單擊 java 文件 SpringbootApplication 並運行
- 你應該看到成功的結果
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
/ Library / Java / JavaVirtualMachines / jdk - 14.0.2.jdk / Contents / Home / bin / java - XX : TieredStopAtLevel = 1 - noverify - Dspring . output . ansi . enabled = always - Dcom . sun . management . jmxremote - Dspring . jmx . enabled = true - Dspring . liveBeansView . mbeanDomain - Dspring . application . admin . enabled = true - javaagent : / Applications / IntelliJ IDEA . app / Contents / lib / idea_rt . jar = 53480 : / Applications / IntelliJ IDEA . app / Contents / bin - Dfile . encoding = UTF - 8 - classpath / Users / appshah / crunchify / intellij / springboot / target / classes : / Users / appshah / . m2 / repository / org / springframework / boot / spring - boot - starter / 2.3.3.RELEASE / spring - boot - starter - 2.3.3.RELEASE.jar : / Users / appshah / . m2 / repository / org / springframework / boot / spring - boot / 2.3.3.RELEASE / spring - boot - 2.3.3.RELEASE.jar : / Users / appshah / . m2 / repository / org / springframework / spring - context / 5.2.8.RELEASE / spring - context - 5.2.8.RELEASE.jar : / Users / appshah / . m2 / repository / org / springframework / spring - aop / 5.2.8.RELEASE / spring - aop - 5.2.8.RELEASE.jar : / Users / appshah / . m2 / repository / org / springframework / spring - beans / 5.2.8.RELEASE / spring - beans - 5.2.8.RELEASE.jar : / Users / appshah / . m2 / repository / org / springframework / spring - expression / 5.2.8.RELEASE / spring - expression - 5.2.8.RELEASE.jar : / Users / appshah / . m2 / repository / org / springframework / boot / spring - boot - autoconfigure / 2.3.3.RELEASE / spring - boot - autoconfigure - 2.3.3.RELEASE.jar : / Users / appshah / . m2 / repository / org / springframework / boot / spring - boot - starter - logging / 2.3.3.RELEASE / spring - boot - starter - logging - 2.3.3.RELEASE.jar : / Users / appshah / . m2 / repository / ch / qos / logback / logback - classic / 1.2.3 / logback - classic - 1.2.3.jar : / Users / appshah / . m2 / repository / ch / qos / logback / logback - core / 1.2.3 / logback - core - 1.2.3.jar : / Users / appshah / . m2 / repository / org / apache / logging / log4j / log4j - to - slf4j / 2.13.3 / log4j - to - slf4j - 2.13.3.jar : / Users / appshah / . m2 / repository / org / apache / logging / log4j / log4j - api / 2.13.3 / log4j - api - 2.13.3.jar : / Users / appshah / . m2 / repository / org / slf4j / jul - to - slf4j / 1.7.30 / jul - to - slf4j - 1.7.30.jar : / Users / appshah / . m2 / repository / jakarta / annotation / jakarta . annotation - api / 1.3.5 / jakarta . annotation - api - 1.3.5.jar : / Users / appshah / . m2 / repository / org / springframework / spring - core / 5.2.8.RELEASE / spring - core - 5.2.8.RELEASE.jar : / Users / appshah / . m2 / repository / org / springframework / spring - jcl / 5.2.8.RELEASE / spring - jcl - 5.2.8.RELEASE.jar : / Users / appshah / . m2 / repository / org / yaml / snakeyaml / 1.26 / snakeyaml - 1.26.jar : / Users / appshah / . m2 / repository / org / slf4j / slf4j - api / 1.7.30 / slf4j - api - 1.7.30.jar com . crunchify . springboot . SpringbootApplication Java HotSpot ( TM ) 64 - Bit Server VM warning : Options - Xverify : none and - noverify were deprecated in JDK 13 and will likely be removed in a future release . . ____ _ __ _ _ / \ \ / ___ '_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | ' _ | '_| | ' _ \ / _ ` | \ \ \ \ \ \ / ___ ) | | _ ) | | | | | | | ( _ | | ) ) ) ) ' | ____ | . __ | _ | | _ | _ | | _ \ __ , | / / / / ========= | _ | ============== | ___ /=/ _ / _ / _ / : : Spring Boot : : ( v2 . 3.3.RELEASE ) 2020 - 08 - 17 12 : 12 : 29.554 INFO 70969 --- [ main ] c . c . springboot . SpringbootApplication : Starting SpringbootApplication on LM - AUN - 11022307 with PID 70969 ( / Users / appshah / crunchify / intellij / springboot / target / classes started by appshah in / Users / appshah / crunchify / intellij / springboot ) 2020 - 08 - 17 12 : 12 : 29.556 INFO 70969 --- [ main ] c . c . springboot . SpringbootApplication : No active profile set , falling back to default profiles : default 2020 - 08 - 17 12 : 12 : 29.772 INFO 70969 --- [ main ] c . c . springboot . SpringbootApplication : Started SpringbootApplication in 0.385 seconds ( JVM running for 0.728 ) Hello . This is 1st Spring Hello World Application in Intellij IDEA by Crunchify . com Process finished with exit code 0 |
祝賀。 您已成功創建 Spring Boot 應用程序。

接下來是什麼?
- 創建偵聽端口 8081 的最簡單的 Web Rest 服務。
- 在 Eclipse IDE 中創建 Spring Boot。