搜尋
首頁Javajava教程如何在Intellij中運行第一個春季啟動應用程序?

Intellij Idea簡化了春季啟動的開發,使其成為Java開發人員的最愛。 它的慣例與配置方法最小化了樣板代碼,從而使開發人員可以專注於業務邏輯。本教程演示了兩種用於在Intellij Idea中創建和運行基本春季啟動應用程序的方法。

>這種強大的IDE促進了具有必要依賴項的項目創建,並導入現有的Spring Boot項目。 在開始之前,請確保您有:

    安裝了Java Development套件(JDK)。
  • Intellij Idea已安裝和配置。
  • 對Java和Spring概念的基本理解。
  • 在Intellij Idea
中設置您的Spring Boot Project

>步驟1:Intellij Ideas安裝

>訪問Intellij Idea網站:
  1. > 單擊“下載”按鈕。
  2. 選擇您的首選版(社區或最終)。
  3. >下載並安裝,按照屏幕上的說明。
  4. 啟動Intellij Idea並完成初始設置。
  5. 步驟2:使用Spring Initializr
  6. 的項目生成項目
>導航到春季啟動式網站:
  1. > >指定項目詳細信息:
  2. 選擇您的Spring Boot版本。
    • 輸入組名稱。
    • 輸入偽影名(例如,
    • )。
    • > newProject選擇所需的依賴項(例如,春季Web)。
    • >
    單擊“生成”以將項目作為zip文件下載。
  3. >

How to Run Your First Spring Boot Application in IntelliJ?>步驟3:創建和配置Spring Boot Project

有兩種方法:使用Spring Initializr或直接在Intellij中創建Maven項目。

>

方法1:使用Spring Initializr

在Intellij Idea中打開下載的zip文件。

  1. 下創建
  2. 軟件包。
  3. > controllernewProject -> src/main/java軟件包中創建一個類
  4. >
  5. > ExampleC controller

How to Run Your First Spring Boot Application in IntelliJ?>將以下代碼添加到

>,確保您導入必要的註釋:>
  1. ExampleC>
  2. 方法2:在Intellij
package org.example.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class ExampleC {
   @RequestMapping("/firstApp")
   @ResponseBody
   public String firstSpringApp(){
      return "Welcome!";
   }
}
中創建一個Maven項目
  1. >在Intellij中創建一個新的Maven項目。
  2. >在pom.xml>標籤中添加以下依賴項:> <dependencies></dependencies>
package org.example.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class ExampleC {
   @RequestMapping("/firstApp")
   @ResponseBody
   public String firstSpringApp(){
      return "Welcome!";
   }
}
>更新Maven配置(安裝階段)。

How to Run Your First Spring Boot Application in IntelliJ?

>將註釋添加到您的主應用程序類中。
    >
  1. @SpringBootApplication

How to Run Your First Spring Boot Application in IntelliJ?>添加

    方法。
  1. SpringApplication.run(Main.class, args); main
  2. 如圖1所述,創建
控制器類別的
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
        <version>2.5.3</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <version>2.5.3</version>
    </dependency>
</dependencies>
>
  1. >步驟4:運行應用程序ExampleC
  2. >單擊工具欄中的綠色“運行”按鈕。 控制台將顯示Tomcat啟動信息(端口8080)。

步驟5:查看結果

>通過How to Run Your First Spring Boot Application in IntelliJ?的瀏覽器訪問該應用程序。您應該看到“歡迎!”。

http://localhost:8080/firstApp

結論

How to Run Your First Spring Boot Application in IntelliJ?

Intellij Idea顯著簡化了Spring Boot應用程序的開發。 無論是使用Spring Initializr還是手動Maven設置,該過程都會簡化,從而有效地創建了可靠和可擴展的應用程序。 利用Intellij Idea的功能以及Spring Boot的“大會對結構”的功能,以進行最佳開發。

以上是如何在Intellij中運行第一個春季啟動應用程序?的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
JVM性能與其他語言JVM性能與其他語言May 14, 2025 am 12:16 AM

JVM'SperformanceIsCompetitiveWithOtherRuntimes,operingabalanceOfspeed,安全性和生產性。 1)JVMUSESJITCOMPILATIONFORDYNAMICOPTIMIZAIZATIONS.2)c提供NativePernativePerformanceButlanceButlactsjvm'ssafetyFeatures.3)

Java平台獨立性:使用示例Java平台獨立性:使用示例May 14, 2025 am 12:14 AM

JavaachievesPlatFormIndependencEthroughTheJavavIrtualMachine(JVM),允許CodeTorunonAnyPlatFormWithAjvm.1)codeisscompiledIntobytecode,notmachine-specificodificcode.2)bytecodeisisteredbytheybytheybytheybythejvm,enablingcross-platerssectectectectectross-eenablingcrossectectectectectection.2)

JVM架構:深入研究Java虛擬機JVM架構:深入研究Java虛擬機May 14, 2025 am 12:12 AM

TheJVMisanabstractcomputingmachinecrucialforrunningJavaprogramsduetoitsplatform-independentarchitecture.Itincludes:1)ClassLoaderforloadingclasses,2)RuntimeDataAreafordatastorage,3)ExecutionEnginewithInterpreter,JITCompiler,andGarbageCollectorforbytec

JVM:JVM與操作系統有關嗎?JVM:JVM與操作系統有關嗎?May 14, 2025 am 12:11 AM

JVMhasacloserelationshipwiththeOSasittranslatesJavabytecodeintomachine-specificinstructions,managesmemory,andhandlesgarbagecollection.ThisrelationshipallowsJavatorunonvariousOSenvironments,butitalsopresentschallengeslikedifferentJVMbehaviorsandOS-spe

Java:寫一次,在任何地方跑步(WORA) - 深入了解平台獨立性Java:寫一次,在任何地方跑步(WORA) - 深入了解平台獨立性May 14, 2025 am 12:05 AM

Java實現“一次編寫,到處運行”通過編譯成字節碼並在Java虛擬機(JVM)上運行。 1)編寫Java代碼並編譯成字節碼。 2)字節碼在任何安裝了JVM的平台上運行。 3)使用Java原生接口(JNI)處理平台特定功能。儘管存在挑戰,如JVM一致性和平台特定庫的使用,但WORA大大提高了開發效率和部署靈活性。

Java平台獨立性:與不同的操作系統的兼容性Java平台獨立性:與不同的操作系統的兼容性May 13, 2025 am 12:11 AM

JavaachievesPlatFormIndependencethroughTheJavavIrtualMachine(JVM),允許Codetorunondifferentoperatingsystemsswithoutmodification.thejvmcompilesjavacodeintoplatform-interploplatform-interpectentbybyteentbytybyteentbybytecode,whatittheninternterninterpretsandectectececutesoneonthepecificos,atrafficteyos,Afferctinginginginginginginginginginginginginginginginginginginginginginginginginginginginginginginginginginginginginginginginginginginging

什麼功能使Java仍然強大什麼功能使Java仍然強大May 13, 2025 am 12:05 AM

JavaispoperfulduetoitsplatFormitiondence,對象與偏見,RichstandardLibrary,PerformanceCapabilities和StrongsecurityFeatures.1)Platform-dimplighandependectionceallowsenceallowsenceallowsenceallowsencationSapplicationStornanyDevicesupportingJava.2)

頂級Java功能:開發人員的綜合指南頂級Java功能:開發人員的綜合指南May 13, 2025 am 12:04 AM

Java的頂級功能包括:1)面向對象編程,支持多態性,提升代碼的靈活性和可維護性;2)異常處理機制,通過try-catch-finally塊提高代碼的魯棒性;3)垃圾回收,簡化內存管理;4)泛型,增強類型安全性;5)ambda表達式和函數式編程,使代碼更簡潔和表達性強;6)豐富的標準庫,提供優化過的數據結構和算法。

See all articles

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

WebStorm Mac版

WebStorm Mac版

好用的JavaScript開發工具

SublimeText3 Linux新版

SublimeText3 Linux新版

SublimeText3 Linux最新版

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

Atom編輯器mac版下載

Atom編輯器mac版下載

最受歡迎的的開源編輯器

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具