2020年10月5日 星期一

從零開始的SpringBoot框架 Chap_00環境設置

 

1.      安裝 JDK

https://adoptopenjdk.net/










VM分別
HotSpot
的爸爸是 Oracle
OpenJ9
的爸爸是 IBM

2.      SpringToolsSuite4下載

https://spring.io/tools











點擊spring-tool-suite-4-4.8.0.RELEASE-e4.17.0-win32.win32.x86_64.self-extracting.jar 解壓縮

3.      Eclipse Encode to UTF-8

Window >> Preferences >> search “Encod”

Set All to UTF-8





















4.      下載安裝 Lombok

https://projectlombok.org/download














lombok jar 複製到 eclipse 目錄下

修改 SpringToolSuite4.ini 最後新增一行

-javaagent:D:\eclipse-sts-4.8.0.RELEASE\lombok.jar


-startup
plugins/org.eclipse.equinox.launcher_1.5.800.v20200727-1323.jar
--launcher.library
plugins/org.eclipse.equinox.launcher.win32.win32.x86_64_1.1.1300.v20200819-0940
-product
org.springframework.boot.ide.branding.sts4
--launcher.defaultAction
openFile
-vm
plugins/org.eclipse.justj.openjdk.hotspot.jre.full.win32.x86_64_14.0.2.v20200815-0932/jre/bin
-vmargs
-Dosgi.requiredJavaVersion=11
-Dosgi.dataAreaRequiresExplicitInit=true
-Xms256m
-Xmx2048m
--add-modules=ALL-SYSTEM
-javaagent:D:\eclipse-sts-4.8.0.RELEASE\lombok.jar










啟動 sts >> help >> about Spring Tools Suite4
看到 Lombok ,安裝完成












5.      Create a Project >> Spring Boot >> Spring Starter Project














maven 設定,可以不改












selected >> SpringWeb

Spring Boot Version >> 2.3.4




















SpringBoot版本說明
PRE: 
預覽版,不建議使用;
SNAPSHOT:
快照版,表示開發版本,隨時可能修改;
Mx:
里程碑版本,測試版本,發佈版本的前兆
RCx: 
候選發佈版本,穩定版本,並不一定會發布
RELEASEx: 
發佈版本
GA:
General Availability,正式發佈的版本。
SpringBoot可用版號與相依

6.      修改DemoApplication.java













package io.samchen.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
@RestController
public class DemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

    @GetMapping("/hello")
    public String hello(@RequestParam(value = "name", defaultValue = "World") String name) {
        return String.format("Hello %s!", name);
    }
}

7.     啟動測試





























8.      瀏覽器測試