Tutorial Series Part 1: Project Setup with Spring Boot 3 and Java 17

Date: December 10, 2024


Welcome to the first part of our Spring Boot 3 and Java 17 tutorial series! In this series, we will build a simple but complete web application step-by-step, covering everything from project setup to testing and deployment.


What You’ll Learn in Part 1

  • How to create a Spring Boot 3 project with Java 17
  • Configuring essential dependencies for a RESTful web application
  • Setting up your development environment and build tool (Maven/Gradle)
  • Basic application structure and running your app locally

Step 1: Create a New Spring Boot 3 Project

We will use Spring Initializr to bootstrap our project quickly.

  • Go to https://start.spring.io/
  • Choose:
  • Project: Maven (or Gradle if preferred)
  • Language: Java
  • Spring Boot: 3.1.x (latest available)
  • Java: 17
  • Group: com.example
  • Artifact: demoapp
  • Packaging: Jar
  • Dependencies:
  • Spring Web (for REST APIs)
  • Spring Data JPA (we’ll use it later)
  • H2 Database (in-memory, for demo)
  • Spring Boot DevTools (for hot reload)
  • Spring Security (we’ll secure the app later)

Click Generate to download the project zip.


Step 2: Import the Project into Your IDE

Open your favorite IDE (IntelliJ IDEA, Eclipse, VS Code) and import the project as a Maven/Gradle project.

Check your pom.xml (or build.gradle) for Spring Boot 3 and Java 17 compatibility. For example, in Maven:

<properties>
    <java.version>17</java.version>
    <spring-boot.version>3.1.2</spring-boot.version>
</properties>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-dependencies</artifactId>
            <version>${spring-boot.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

Step 3: Create a Simple REST Controller

Let’s create a basic GreetingController to verify that our app is up and running.

package com.example.demoapp.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class GreetingController {

    @GetMapping("/hello")
    public String sayHello() {
        return "Hello, Spring Boot 3 with Java 17!";
    }
}

Step 4: Run Your Application

Run the app with:

./mvnw spring-boot:run
# or
./gradlew bootRun

Or directly from your IDE’s run configuration.

Open your browser or use curl to test:

curl http://localhost:8080/hello
# Output: Hello, Spring Boot 3 with Java 17!

Congrats! Your first Spring Boot 3 app is running.


Step 5: Configure Application Properties

We can configure our app in src/main/resources/application.properties. For now, let’s enable the H2 console to inspect the database later:

spring.h2.console.enabled=true
spring.datasource.url=jdbc:h2:mem:testdb

Visit http://localhost:8080/h2-console to open the H2 web console (user: sa, no password).


Summary

Today, you learned how to:

  • Bootstrap a Spring Boot 3 project using Java 17
  • Add essential dependencies
  • Create a simple REST endpoint
  • Run and test your app locally

What’s Next?

In Part 2, we’ll dive into designing REST APIs and controllers with request validation and error handling — essential skills for building robust backend services.

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *