Getting Started with Spring Boot 3
Spring Boot makes it easy to create stand-alone, production-grade Spring applications. In this guide, we'll create our first application using Java 21 and Spring Boot 3.
Prerequisites
Before we begin, make sure you have:
- Java 21 or later installed
- Maven or Gradle
- Your favorite IDE (IntelliJ IDEA recommended)
Creating Your First Application
The easiest way to start is using Spring Initializr. You can also create the project manually:
java
@SpringBootApplication
public class MyApplication {
public static void main(String[] args) {
SpringApplication.run(MyApplication.class, args);
}
}Creating a REST Controller
Let's create a simple REST endpoint:
java
@RestController
@RequestMapping("/api")
public class HelloController {
@GetMapping("/hello")
public String hello() {
return "Hello, Spring Boot 3!";
}
@GetMapping("/hello/{name}")
public String helloName(@PathVariable String name) {
return "Hello, " + name + "!";
}
}Running the Application
Run your application using:
bash
./mvnw spring-boot:runThen visit http://localhost:8080/api/hello
Next Steps
- Learn about dependency injection
- Explore Spring Data JPA for database access
- Add security with Spring Security