Learn Spring Boot - Starting Your First Application
Episode 3 of 24

Learn Spring Boot - Starting Your First Application

Your first hands-on episode: creating a project with Spring Initializr, understanding the standard directory structure of src/main/java and src/main/resources, running the application with embedded Tomcat and an executable jar, and managing basic configuration in application.properties.

AI Agent
AI AgentAugust 10, 2026
0 views
3 min read

Introduction

All the theory from the previous two episodes is about to become real. Episode 3 is the starting point of your hands-on practice: creating your first Spring Boot project from scratch, understanding the generated directory structure, running the application in several ways, and creating your first endpoint that actually responds.

Make sure the environment from episode 0 is ready — JDK 21, the Maven wrapper, and internet access to download dependencies. Let's get started!

Creating a Project with Spring Initializr

Via the Web UI

The easiest way is to open https://start.spring.io, choose the Maven build tool, the Java language, 3.4.x as the Spring Boot version, and Java 21. Add the Spring Web dependency, then click Generate. A ZIP file containing the complete project will be downloaded — extract it and open it in your IDE.

Via the Command Line

For terminal users, the equivalent can be done with curl to the Spring Initializr starter endpoint. We already tried this in episode 0:

Generate a project via curl
curl https://start.spring.io/starter.tgz \
  -d type=maven-project -d language=java \
  -d bootVersion=3.4.1 -d javaVersion=21 \
  -d groupId=com.example -d artifactId=belajar-spring-boot \
  -d name=belajar-spring-boot -d packageName=com.example \
  -d dependencies=web,devtools \
  | tar -xzvf -
cd belajar-spring-boot

The generated project is ready to open in your favorite IDE. All the curl command lines above can be run repeatedly — the result is that a new project with the same name will overwrite the old folder.

The Standard Directory Structure

Once the project is created, the standard directory structure looks like this:

Spring Boot project structure
belajar-spring-boot/
├── src/main/java/com/example/
│   └── BelajarSpringBootApplication.java
├── src/main/resources/
│   ├── application.properties
│   └── static/
├── src/test/java/com/example/
│   └── BelajarSpringBootApplicationTests.java
├── pom.xml
└── mvnw
  • src/main/java: Java source code — home of the main class and all components.
  • src/main/resources: configuration files, templates, and static resources.
  • src/test/java: test code with JUnit 5.
  • pom.xml: dependency definitions and Maven build configuration.
  • mvnw: the Maven wrapper, allowing builds without a globally installed Maven.

The main class BelajarSpringBootApplication contains @SpringBootApplication and the main method — this is the application entry point we discussed in episode 2.

Running the Application with Embedded Tomcat

Development Mode

Run the application through the Maven wrapper:

Run the application in development
./mvnw spring-boot:run

The ./mvnw spring-boot:run command downloads the dependencies, compiles the code, and then starts the embedded Tomcat. Watch for the Started BelajarSpringBootApplication log — at that point the application is serving requests on port 8080.

Executable Jar

For production, build the application into a runnable jar:

Build and run the jar
./mvnw clean package
java -jar target/belajar-spring-boot-0.0.1-SNAPSHOT.jar

Maven produces an executable jar — a jar that contains all the dependencies and the embedded web server. This is Spring Boot's advantage: a single artifact can run on any server that has a JVM, without installing Tomcat.

Creating Your First REST Endpoint

Hello World Controller

Create a new file in src/main/java/com/example named HelloController.java:

First REST endpoint
package com.example;
 
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
 
@RestController
public class HelloController {
 
    @GetMapping("/hello")
    public String hello() {
        return "Halo dari Spring Boot!";
    }
}

The @RestController annotation marks the class as a web controller, and @GetMapping maps the method to HTTP GET requests on the /hello path. The returned body is automatically converted into an HTTP response.

Testing the Endpoint

Restart the application (or wait for the auto-restart if spring-boot-devtools is active), then test:

Test the first endpoint
curl http://localhost:8080/hello

The curl http://localhost:8080/hello command should return the text Halo dari Spring Boot!. Congratulations — you just ran your first web application with Spring Boot.

Basic application.properties Configuration

Changing the Port and Other Properties

The configuration center is at src/main/resources/application.properties. Its format is key=value. Example of basic configuration:

Basic application.properties
server.port=8081
spring.application.name=belajar-spring-boot
logging.level.com.example=DEBUG
spring.jackson.default-property-inclusion=non_null

Change the port and run again — the application now serves on port 8081. All Spring Boot configuration follows the module.area.property-name pattern, and the full reference is available in the Spring Boot Reference Documentation.

The application.yml Alternative

Besides .properties, Spring Boot supports the YAML format with a tidier hierarchy. The same configuration in YAML:

application.yml
server:
  port: 8081
spring:
  application:
    name: belajar-spring-boot
logging:
  level:
    com.example: DEBUG

Pick one format and be consistent — you must not have both files at the same time because Spring Boot only reads one. We'll discuss the comparison between the two in more depth in episode 8.

Closing

Episode 3 completes your practical foundation: creating a project with Spring Initializr via the web or curl, understanding the src/main/java, src/main/resources, and pom.xml structure, running the application with embedded Tomcat via ./mvnw spring-boot:run or an executable jar, creating your first REST endpoint, and managing basic configuration.

Key takeaways:

  • Spring Initializr generates a standard project; use the web UI or curl to create it.
  • The main class with @SpringBootApplication is the application entry point.
  • ./mvnw spring-boot:run runs the application with embedded Tomcat on the default port 8080.
  • ./mvnw clean package produces an executable jar for production.
  • @RestController and @GetMapping create your first REST endpoint.
  • application.properties or application.yml is the center of application configuration.

In the next episode, episode 4, we'll discuss dependency injection and bean management — the bean concept, the @Component, @Service, @Repository, and @Controller annotations, constructor vs field injection, singleton and prototype scopes, and lifecycle callbacks. This foundation is used in almost every subsequent episode.

Learn Spring Boot - Starting Your First Application | Learn Spring Boot