Spring Boot Project Creation: IntelliJ IDEA & Spring Initializr
Spring Boot simplifies the configuration and setup of production-ready Java applications. This guide walks through bootstrapping a Spring Boot application using Spring Initializr, importing it into IntelliJ IDEA, understanding foundational build configurations, analyzing runtime logs, and constructing a functional REST API endpoint.
1. Development Setup Strategy
Building a Spring Boot application efficiently requires choosing tools that reduce operational overhead and simplify project management.
- IntelliJ IDEA as the Primary IDE: IntelliJ IDEA offers an active update cycle, strong refactoring support, and intuitive navigation for Java and Spring ecosystems.
- Spring Initializr (
start.spring.io): A browser-based initialization tool curated by the Spring team. It abstracts manual XML file generation, dependency version management, and folder scaffolding, enabling developers to configure and generate downloadable project baselines.
2. Spring Initializr Configurations & Project Metadata
When initializing a Spring Boot project via Spring Initializr, project characteristics are defined using key fields:
Build Tool Selection: Maven vs. Gradle
A build tool automates repetitive software engineering lifecycle tasks, including compiling code, managing external dependencies, running tests, and bundling executable artifacts.
- Maven: Uses
pom.xml(Project Object Model) configuration files to manage dependencies and build phases. It converts source code into a executable format (JAR or WAR) with a single command or button click. - Gradle: Uses Groovy or Kotlin DSL scripts for flexible, programmatic build scripts.
Spring Boot Version Classifications
Spring Initializr lists several version tags for the framework:
- Snapshot Releases (e.g.,
3.2.0 (SNAPSHOT)): Nightly builds under active development. These contain cutting-edge features but may be unstable. - Milestone Releases (e.g.,
3.2.0 (M2)): Pre-release builds containing feature-complete milestones intended for community testing. - Release / GA Versions (e.g.,
3.1.5or3.2.0without suffixes): Stable, production-ready releases recommended for development.
Project Metadata Definitions
- Group: Identifies the project uniquely across all projects, typically following reverse domain name convention (e.g.,
com.edigest). - Artifact: The name of the jar/war binary generated during compilation (e.g.,
my-first-project). It serves as the project's human-readable identifier. - Description: Textual context describing the application's core function.
- Package Name: The default package path under which all Java source files reside (e.g.,
com.edigest.myfirstproject). - Java Version: Defines the target Java Virtual Machine (JVM) compatibility (e.g., Java 8, 11, 17, or 21).
3. Managing Dependencies & Spring Web
Dependencies are modular, external libraries integrated into a project to avoid re-inventing baseline application features (such as database connections or HTTP communication).
Spring Web Starter (spring-boot-starter-web)
When building Web APIs or Web Applications, adding Spring Web supplies the necessary libraries for HTTP request handling and RESTful service development.
Key Architectural Advantage: Embedded Server
Including Spring Web automatically transitively imports an Embedded Apache Tomcat Container.
Note: Traditional Java web applications required installing, configuring, and deploying project artifacts manually into an external web server instance (e.g., a standalone Tomcat installation). Embedded Tomcat runs directly inside the JVM process alongside the Spring Boot code, eliminating external web server management.
4. Packaging Models: Executable JAR vs. Deployment WAR
Spring Boot applications support two main archive packaging formats:
For microservices and modern containerized deployments, JAR packaging is the industry default due to its self-contained structure.
5. IDE Setup & Importing the Project
Once project parameters are defined on Spring Initializr, clicking Generate downloads a compressed archive (.zip).
Import Workflow
- Extract the downloaded
.zipfile into a dedicated workspace directory. - Launch IntelliJ IDEA.
- Drag and drop the unzipped root folder directly into the IntelliJ interface (or navigate via
File -> Open). - Select Trust Project if prompted by IntelliJ's security wizard.
Project Structure Alignment (JDK Configuration)
If project build errors occur upon initial load, verify the Java Development Kit (JDK) alignment inside IntelliJ IDEA:
- Navigate to File Project Structure Project.
- Verify that the SDK setting corresponds to or exceeds the target version defined in Spring Initializr (e.g., JDK 11 or JDK 17).
- Ensure the project language level matches the SDK version.
6. Execution Flow & Console Log Deconstruction
Running the primary application file (MyFirstProjectApplication.java) bootstraps the Spring Application Context.
package com.edigest.myfirstproject;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class MyFirstProjectApplication {
public static void main(String[] args) {
SpringApplication.run(MyFirstProjectApplication.class, args);
}
}
Decoding Runtime Console Output
When launched, the console produces operational logging artifacts:
Key Console Indicators:
- Spring ASCII Banner & Version: Confirms the framework release operating in runtime memory.
- Process ID (
PID): Represents the unique operating system process assigned to the running JVM instance (e.g.,PID 18873). This process ID is useful when monitoring OS resources or troubleshooting stuck processes. - Active Profiles: Indicates active configuration profiles (e.g.,
dev,prod). If unset, Spring defaults todefault. - Tomcat Initialization: Confirms that Embedded Apache Tomcat has bound to HTTP port
8080with an empty root context path ("").
7. Request Routing Architecture: Host, Port, and Context Path
To interact with a running Spring Boot web application, web clients execute HTTP requests directed at structured URLs.
Web URL Breakdown
http://localhost:8080/ABC
|____| |_______| |__| |__|
| | | |
Protocol Host Port Endpoint/Mapping
- Host (
localhost/127.0.0.1): Points to the local machine loopback address. - Port (
8080): Identifies the specific network port bound to the embedded Tomcat server instance.- If a client attempts to connect to an unassigned port (e.g.,
http://localhost:8081), the operating system rejects the connection:This site can't be reached/Connection refused.
- If a client attempts to connect to an unassigned port (e.g.,
- Context Path: The root base path assigned to an application deployed on a server.
- By default, Spring Boot initializes with an empty context path (
""), meaning requests map directly to/. - If a context path is defined (e.g.,
/my-project), all endpoint requests must be prefixed accordingly (http://localhost:8080/my-project/ABC).
- By default, Spring Boot initializes with an empty context path (
- Endpoint Path (
/ABC): The explicit route mapped to a specific controller method inside the Java application.
8. Building Your First REST API Endpoint
To expose HTTP APIs, Spring Boot uses specialized annotations that declare request handlers.
Creating a Controller Class
- Create a new Java class inside the project package structure (e.g.,
MyClassName.java). - Annotate the class with
@RestControllerto register it as a Web Request Handler that outputs direct response payloads. - Define a public controller method returning a response payload (
String). - Annotate the method with
@GetMapping("/ABC")to bind HTTPGETrequests sent to the/ABCroute.
package com.edigest.myfirstproject;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* REST Controller providing HTTP endpoint routes.
*/
@RestController
public class MyClassName {
/**
* Endpoint mapping for HTTP GET requests aimed at /ABC
*
* @return Raw string payload returned directly to the calling HTTP client.
*/
@GetMapping("/ABC")
public String sayHello() {
return "hello";
}
}
Operational End-to-End Request Flow
Browser Client
|
| HTTP GET request: http://localhost:8080/ABC
v
Embedded Apache Tomcat (Listening on Port 8080)
|
| Intercepts HTTP request and hands off to Spring DispatcherServlet
v
Spring MVC Handler Mapping
|
| Identifies @RestController (MyClassName) matching route "/ABC"
v
MyClassName.sayHello()
|
| Method executes and returns string "hello"
v
Embedded Tomcat / Spring MVC
|
| Wraps payload into HTTP Response Body (Status: 200 OK)
v
Browser Client Displays Output Payload: "hello"
Verification
- Navigating to
http://localhost:8080/(unmapped root path) returns an expected404 Not Foundresponse because no controller logic handles/. - Navigating explicitly to
http://localhost:8080/ABCexecutessayHello()and outputs"hello"directly inside the browser window.
Summary and Key Takeaways
- Spring Initializr (
start.spring.io): A web initialization tool that scaffolds Spring Boot project files, sets metadata, and organizes initial dependencies. - Build Automation via Maven: Maven simplifies compilation, testing, and dependency packaging into runnable target artifacts (
JARorWAR). - Embedded Server Deployment: Spring Boot applications using
spring-boot-starter-webpackage an Embedded Apache Tomcat Container, allowing applications to run independently without external application server deployments. - JAR vs. WAR: Standard JAR files run directly using
java -jar app.jarvia an embedded web server, whereas WAR files require deployment to a separate web server. - Process Tracking: When booted, Spring applications print operational parameters, including an assigned Operating System Process ID (
PID) and active server ports. - URL Anatomy & Routing: HTTP web routing relies on the combination of Host (
localhost), Network Port (8080), Context Path (default root/), and Endpoint Mappings (/ABC). - REST API Generation: Annotating a class with
@RestControllerand its internal methods with@GetMapping("/path")exposes Java logic as reachable HTTP endpoints.