Setting Up a Modern Spring Boot Web Server with REST API & Web Content (2025 Guide)
Software engineer and founder with a background in finance and tech. Currently building aVenture.vc, a platform for researching private companies. Based in San Francisco.

Related Java Setup Guides
- Core Guide: Java, Maven & Gradle Setup & Usage
- Specifics: Setting up JavaFX
This Article: Specifics for Setting up a Spring Boot Server
Overview
Build Tool Setup (Maven/Gradle): JDK, Maven, and Gradle setup (including
Core Java & Build Tools Setup GuideJAVA_HOME/M2_HOME) are covered in the. While this article primarily demonstrates a Maven-based Spring Boot project, Gradle is a well-supported alternative, and the linked guide provides details for both.
IntelliJ IDEA Spring Initializr: For easy project generation.
REST API Endpoint: A simple "Hello World" example.
Static Web Content: Serving HTML/CSS/JS.
Application Configuration: Using
application.propertiesand environment variables.
Part 1: Create a Spring Boot Project
Generate project via CLI (start.spring.io)
curl to fetch and unpack a new Spring Boot starter:Project structure
src/main/java: Application code (MySpringBootAppApplication.java).src/main/resources/static: Static assets (HTML, CSS, JS).src/main/resources/application.properties: Configuration for the application.pom.xml: Maven configuration and dependency management.
Part 2: Application Configuration
application.properties setup
Edit src/main/resources/application.properties to configure your application:
For different environments, create profile-specific properties:
application-dev.propertiesapplication-prod.properties
Environment variables with .env
For sensitive data like API keys, use environment variables.
- Add spring-dotenv dependency to
pom.xml:
- Create
.env.examplefile:
SERVER_PORT=8080
CUSTOM_API_KEY=your-api-key-here
- Create your actual
.envfile (don't commit to git):
SERVER_PORT=8080
CUSTOM_API_KEY=actual-api-key-value
- Reference env variables in
application.properties:
Part 3: Build a Basic REST API
HelloController.java
Create src/main/java/com/example/myspringbootapp/HelloController.java:
Run and test
-
Run in IntelliJ: click the green play icon next to
mainmethod -
CLI:
bash
Visit http://localhost:8080/hello and http://localhost:8080/hello?name=Spring or use:
Part 4: Serve Static Web Content
Static index.html
-
Create
src/main/resources/static/index.html:html -
Restart app and browse to http://localhost:8080/ Spring Boot serves files in
static/automatically.
Part 5: Essential Maven Commands for Spring Boot
Refer to the Core Maven Guide for general Maven commands. Specific to Spring Boot (using the Spring Boot Maven Plugin, typically included):
Spring Boot Maven Plugin Commands
Use spring-boot:run for development. For other standard Maven lifecycle commands like clean, compile, test, install, use them as described in the Core Maven Guide.
Part 6: Development & Hot Reload
Hot reload setup with Spring Boot DevTools
Spring Boot DevTools (spring-boot-devtools dependency) enables automatic restart when compiled files on the classpath change. To optimize:
- For IntelliJ IDEA:
- In Preferences > Build, Execution, Deployment > Compiler, enable "Build project automatically"
- Enable advanced settings: Registry (Ctrl+Alt+Shift+/) > check "compiler.automake.allow.when.app.running"
- For CLI:
After editing Java sources, run ./mvnw compile in a second terminal to update the classpath and trigger a DevTools restart.
- To run with specific profile:
Part 7: Key Spring Boot Concepts & Troubleshooting
Spring Boot Auto-configuration
Spring Boot automatically configures your application based on the JAR dependencies you have
added. For example, if spring-boot-starter-web is on the classpath, it auto-configures Tomcat
and Spring MVC.
Starters
Spring Boot "Starters" are convenient dependency descriptors that you can include in your
application. For example, spring-boot-starter-data-jpa for JPA/Hibernate,
spring-boot-starter-security for security.
Port Conflict
If port 8080 is in use, change it in application.properties (e.g., server.port=8081) or via
command line:
Maven Central Repository
Maven Central ( central.sonatype.com) is the primary public repository for Java libraries (dependencies). Spring Boot dependencies are typically fetched from here or other configured repositories (like Spring Milestones/Snapshots).
Part 8: Deployment Options
Package for Production (Executable JAR)
java -jar target/myspringbootapp-0.0.1-SNAPSHOT.jar (adjust filename).Running with Different Profiles in Production
When running in production, set environment variables externally:
Docker deployment
- Create
Dockerfile:
- Build and run:








