Master Spring Boot 3: From Environment Setup to a Running Hello‑World REST API

This comprehensive guide walks Java beginners through installing IDEA and JDK, explains Spring Boot 3 fundamentals, demonstrates project creation with Spring Initializr, shows Maven standard layout, configures a simple Hello World REST controller, and covers essential topics such as POM files, GAV coordinates, Maven Wrapper, static resources, templates and unit testing.

Java One
Java One
Java One
Master Spring Boot 3: From Environment Setup to a Running Hello‑World REST API

1. Preparation

Before starting, ensure you have basic Java knowledge and can compile and run simple Java programs. Install a suitable IDE (e.g., JetBrains IDEA Community Edition) and a JDK version not lower than 17.

Install IDEA (download from the official JetBrains site).

Install a compatible JDK.

2. Spring Overview

Spring is a popular framework for building Java applications. Spring Boot simplifies development by handling dependency management, auto‑configuration, and embedded servers (Tomcat, Jetty, Undertow). It does not replace Spring MVC or Spring REST; rather, it builds on top of them.

2.1 Spring Boot Benefits

Reduces manual configuration.

Provides automatic configuration based on classpath.

Helps resolve dependency conflicts (Maven/Gradle).

Includes embedded HTTP servers for quick startup.

2.2 Relationship with Spring

Spring Boot uses the core Spring framework underneath.

It simplifies Spring usage.

2.3 Spring Initializr

The Spring Initializr (http://start.spring.io) lets you generate a project skeleton. You can select the build tool (Maven or Gradle), Java version, packaging (JAR), and dependencies (e.g., Spring Web).

3. Spring Boot Demo

3.1 Create Project with Spring Initializr

Visit the Spring Initializr website and configure the project (Maven, Java 21, Spring Boot 3.5.4, packaging JAR, add Spring Web).

Click GENERATE to download the .zip file.

Extract the archive.

Import the project into IDEA.

3.2 Run the Project

After importing, Maven will resolve dependencies. Run the application with: $ java -jar mycoolapp.jar The embedded Tomcat server starts on port 8080. Accessing http://localhost:8080/ initially shows an error page because no controller is defined yet.

3.3 Add a REST Controller

Create a package com.greenbook.springbootdemo.rest and add the following class:

@RestController
public class FunRestController {
    @GetMapping("/")
    public String sayHello() {
        return "Hello World!";
    }
}

Restart the application and visit http://localhost:8080/ to see "Hello World!".

3.4 Maven Standard Directory Structure

A typical Maven project contains: pom.xml – project metadata, dependencies, plugins. src/main/java – Java source code. src/main/resources – configuration files. src/main/resources/static – static assets (CSS, JS, images). src/main/resources/templates – template files (Thymeleaf, FreeMarker, Mustache). src/test/java – unit tests.

3.5 POM File Details

The pom.xml defines the groupId, artifactId, and version (GAV). Example:

<groupId>com.greenbook</groupId>
<artifactId>springbootdemo</artifactId>
<version>0.0.1-SNAPSHOT</version>

Dependencies are added inside the <dependencies> section, e.g.,

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <version>3.5.4</version>
</dependency>

3.6 Maven Wrapper

The wrapper scripts ( mvnw for Unix/macOS and mvnw.cmd for Windows) ensure the correct Maven version is used without requiring a local installation. Run commands like:

# Windows
> mvnw clean compile test
# Linux/macOS
$ ./mvnw clean compile test

If Maven is already installed, you can use the regular mvn command.

3.7 Source Code Layout

All Java code resides under src/main/java/com.greenbook.springbootdemo. Packages are organized by feature, e.g., a rest package for controllers.

3.8 Application Configuration

The default configuration file src/main/resources/application.properties may contain built‑in Spring Boot settings and custom properties:

# Spring Boot built‑in
server.port=8848

# Custom property
coach.name=MickeyMouse

Custom values can be injected with @Value("${coach.name}") in beans.

3.9 Static Resources

Place static files (images, CSS, JS) in src/main/resources/static. They are served automatically when the application runs as a JAR.

3.10 Template Engines

Spring Boot auto‑configures template engines such as FreeMarker, Thymeleaf, and Mustache. Templates are placed in src/main/resources/templates.

3.11 Unit Testing

Test classes belong in src/test/java. A simple test example:

@SpringBootTest
public class DemoApplicationTests {
    @Test
    void contextLoads() {}
}

4. Additional Resources

Useful Maven repositories for locating dependencies:

https://mvnrepository.com/

https://central.sonatype.com/

https://repo1.maven.org/maven2

Spring Initializr UI
Spring Initializr UI
IDEA project view
IDEA project view
Application log after start
Application log after start
Hello World response in browser
Hello World response in browser
Maven directory structure
Maven directory structure
Maven dependency resolution flowchart
Maven dependency resolution flowchart
Maven local vs remote repository
Maven local vs remote repository
JavamavenSpring BootREST APItutorialIDE
Java One
Written by

Java One

Sharing common backend development knowledge.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.