第一個Spring Boot專案
1、正常創建一個最基礎的Maven專案
2、在pom檔案中添加Spring Boot起步依賴
- Spring Boot專案要繼承Spring Boot的起步依賴spring-boot-starter-parent
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.0.RELEASE</version>
<relativePath/>
</parent>
- Spring Boot完成web專案所需的web啟動器
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
3、撰寫Spring Boot引導類
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class SpringbootApplication {
public static void main(String[] args) {
SpringApplication.run(SpringbootApplication.class, args);
}
}
4、撰寫測驗介面Controller
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class HelloController {
@ResponseBody
@RequestMapping("hello")
public String hello(){
return "hello spring Boot";
}
}
5、啟動執行
番外
1、修改埠號
- resources資源檔案中的組態檔中加如下代碼
server.port=80
2、修改banner圖片
- resources資源檔案中建立banner.txt檔案
- 加入文字圖即可
3、Spring Boot專案熱部署
3.1、什么是熱部署
? 在開發中,我們需要反復的修改類、頁面等資源;每次修改后都需要重新啟動專案,這無疑浪費了我們大量的實踐,因此,我們需要對專案進行配置,使我們修改代碼后不重啟專案即可生效,此程序我們稱之為熱部署,
3.2、匯入熱部署依賴
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
3.3、設定IDEA自動編譯

設定完成后---> 【Shift+Ctrl+Alt+/】--->點擊Registry

轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/174993.html
標籤:Java
上一篇:java中的垃圾處理機制
