105 words
1 minutes
[SpringBoot] #1 Starting SpringBoot
ENVIRONMENT: zshrc, macos, 32G RAM
Prepare
Install SDK
- Add
curl -s "https://get.sdkman.io" | bash
Install JAVA
sdk install java 21.0.2-open- add
export "JAVA_HOME=\$(/usr/libexec/java_home)"to~/.zshrc
** Install MAVEN
sdk install maven
Create Spring Boot Project
- Setup and create sprint boot project from spring initializr
- Java 21 >> 3.2.4 >> Jar
- Dependencies - Spring Web
- Add hello world at
src/main/java/com/example/demo/DemoApplication.java
package com.example.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);
}
}
- Execute
./gradlew bootRun- or
mvn spring-boot:run
RUN
http://localhost:8080/hello
You can see the your first application with web in the localhost 😆
