Creating a project with Spring Initializr
40 min · Beginner
Need help? Ask a tutor on WhatsApp (opens in a new tab)Every ShopLite project must start with the right Java version, the right Boot version and the right folders. One wrong setting can cost an hour later, so nobody writes this setup by hand.
start.spring.io: the project form
Spring Initializr is the official Spring Boot project generator: you fill in a short form at start.spring.io and it gives you a zip file with a ready-to-run Maven project.
Each field of the form ends up in pom.xml or in a folder name. Fill it in as below for ShopLite; Example 1 then asks for the same project with one terminal command.
- Project: Maven. Language: Java.
- Spring Boot: the newest 4.1.x that is not marked SNAPSHOT or M (4.1.1 when this was written).
- Group:
com.shoplite. Artifact:shoplite-api. Name:shoplite-api. Description:ShopLite REST API. Package name:com.shoplite. - Packaging: Jar. Java: 17.
- Dependencies: click Add Dependencies and pick Spring Web (see the next section).
- Click Generate, then unzip
shoplite-api.zip.
Example 1 · The same project from the terminal
Runs in: a terminal with internet access
curl -s https://start.spring.io/starter.zip -d type=maven-project -d language=java -d bootVersion=4.1.1 -d javaVersion=17 -d groupId=com.shoplite -d artifactId=shoplite-api -d name=shoplite-api -d packageName=com.shoplite -d packaging=jar -d dependencies=web -o shoplite-api.ziptar -tf shoplite-api.zip.gitattributes .gitignore HELP.md .mvn/ .mvn/wrapper/ .mvn/wrapper/maven-wrapper.properties src/ src/test/ src/test/java/ src/test/java/com/ src/test/java/com/shoplite/ src/test/java/com/shoplite/ShopliteApiApplicationTests.java src/main/ src/main/resources/ src/main/resources/templates/ src/main/resources/static/ src/main/resources/application.properties src/main/java/ src/main/java/com/ src/main/java/com/shoplite/ src/main/java/com/shoplite/ShopliteApiApplication.java pom.xml mvnw.cmd mvnw
What this code does
- start.spring.io also answers plain HTTP requests. Each
-dis one form field, anddependencies=webis Spring Web. The zip is the same one the Generate button gives. tar -tflists the zip's contents without unzipping; it works on Windows 10 and later and on macOS. You get the wrapper (mvnw,mvnw.cmd,.mvn),pom.xml, one main class, one test andapplication.properties.
The group is a reverse domain name that identifies who made the project; the artifact is the project's own name. Together with the package name they decide the folders your Java code goes in: src/main/java/com/shoplite.
Choosing dependencies: Spring Web to start
A dependency on the Initializr page is a ready-made feature you tick, and each one becomes a starter in pom.xml. For a REST API you need only Spring Web: its description says it builds RESTful applications with Spring MVC and Tomcat. In Spring Boot 4 it adds spring-boot-starter-webmvc, plus spring-boot-starter-webmvc-test for tests.
Start small. ShopLite adds more starters later, each in the module that teaches it: Validation, JDBC with the MySQL driver, and Actuator. Adding a starter later is one <dependency> block in pom.xml, so nothing is lost by waiting.
What can go wrong: ticking everything that looks useful. A JPA or JDBC starter with no database settings makes the app fail at startup, because Boot tries to connect to a database that is not configured yet.
- Now: Spring Web (Spring Web MVC + Tomcat + Jackson).
- Later in this section: Validation, JDBC, MySQL Driver, Actuator.
- Section 16: Spring Data JPA and Flyway. Section 17: Spring Security.
Opening the project in IntelliJ IDEA or VS Code
Open the folder that contains pom.xml, not a single Java file. The IDE reads pom.xml, downloads the libraries and marks src/main/java as source code. The first import downloads about 20 MB and can take a few minutes.
Check that the IDE uses JDK 17 or newer for this project. An IDE can use a different JDK from your terminal, and an old one there causes the same "release version not supported" error you will see below.
- IntelliJ IDEA: File → Open, select the
shoplite-apifolder, click Trust Project. Check the JDK under File → Project Structure → Project → SDK. - VS Code: install the Extension Pack for Java, then File → Open Folder and pick
shoplite-api. Wait for "Java: Ready" in the status bar. - Run from the IDE: open
ShopliteApiApplication.javaand click the green run arrow next tomain. - Wait for the import to finish before running. Red underlines during the import usually disappear by themselves.
Running with the Maven wrapper: mvnw spring-boot:run
The Maven wrapper is the pair of scripts mvnw (macOS, Linux) and mvnw.cmd (Windows) in the project folder; it downloads the exact Maven version the project wants and runs it.
Example 2 runs the generated project. The run works when the log ends with Started ShopliteApiApplication; Example 3 then calls it.
Example 2 · A successful first run
Runs in: the shoplite-api Spring Boot project
mvnw spring-boot:run. ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v4.1.1) 2026-10-16T08:32:38.075+05:30 INFO 6460 --- [shoplite-api] [ main] com.shoplite.ShopliteApiApplication : Starting ShopliteApiApplication using Java 19.0.2 with PID 6460 (C:\Users\asha\shoplite-api\target\classes started by asha in C:\Users\asha\shoplite-api) 2026-10-16T08:32:38.085+05:30 INFO 6460 --- [shoplite-api] [ main] com.shoplite.ShopliteApiApplication : No active profile set, falling back to 1 default profile: "default" 2026-10-16T08:32:42.384+05:30 INFO 6460 --- [shoplite-api] [ main] o.s.boot.tomcat.TomcatWebServer : Tomcat initialized with port 8080 (http) 2026-10-16T08:32:42.479+05:30 INFO 6460 --- [shoplite-api] [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat] 2026-10-16T08:32:42.480+05:30 INFO 6460 --- [shoplite-api] [ main] o.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/11.0.24] 2026-10-16T08:32:43.195+05:30 INFO 6460 --- [shoplite-api] [ main] b.w.c.s.WebApplicationContextInitializer : Root WebApplicationContext: initialization completed in 5002 ms 2026-10-16T08:32:44.803+05:30 INFO 6460 --- [shoplite-api] [ main] o.s.boot.tomcat.TomcatWebServer : Tomcat started on port 8080 (http) with context path '/' 2026-10-16T08:32:44.826+05:30 INFO 6460 --- [shoplite-api] [ main] com.shoplite.ShopliteApiApplication : Started ShopliteApiApplication in 8.786 seconds (process running for 13.588) 2026-10-16T08:32:46.408+05:30 INFO 6460 --- [shoplite-api] [io-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet' 2026-10-16T08:32:46.416+05:30 INFO 6460 --- [shoplite-api] [io-8080-exec-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet' 2026-10-16T08:32:46.425+05:30 INFO 6460 --- [shoplite-api] [io-8080-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 9 ms
What this code does
- Maven first prints its build lines (left out here), then the app starts: the Spring banner, the Java version and process id, Tomcat on port 8080, and
Started ShopliteApiApplication in 8.786 seconds. - The three
DispatcherServletlines appear only after the first request arrives. Times, the process id and paths differ on your computer.
Example 3 · Calling the new app: a 404 that proves it works
Runs in: the shoplite-api Spring Boot project
curl http://localhost:8080/{"timestamp":"2026-10-16T03:02:46.734Z","status":404,"error":"Not Found","path":"/"}What this code does
- The app has no endpoints yet, so every path is
404 Not Found. The JSON body comes from Spring Boot's built-in error handling, which means the server is running and answering. - A browser shows the same error as a Whitelabel Error Page. Your timestamp will differ.
The wrapper makes the project build the same way on every computer, even one with no Maven installed. Open a terminal in the shoplite-api folder and run .\mvnw spring-boot:run in PowerShell, or ./mvnw spring-boot:run on macOS and Linux (plain mvnw also works in Command Prompt). spring-boot:run compiles the code and starts the app, which keeps waiting for requests until you press Ctrl+C.
Then open http://localhost:8080 in a browser. On macOS, zsh: permission denied: ./mvnw means the script lost its run permission while unzipping; fix it once with chmod +x mvnw.
Order of execution
First run, in order
Put the steps of a first run in the right order.
First-run problems: wrong JDK and port 8080 in use
A port is a numbered door on your computer that only one program at a time can listen on; a Spring Boot web app listens on port 8080 by default.
Example 4 fails because the JDK is too old, and Example 5 because port 8080 is busy. Example 6 finds the program that holds the port.
Example 4 · Wrong JDK: release version not supported
Runs in: the shoplite-api Spring Boot project
mvnw spring-boot:run[INFO] --- compiler:3.15.0:compile (default-compile) @ shoplite-api --- [INFO] Recompiling the module because of changed source code. [INFO] Compiling 1 source file with javac [debug parameters release 21] to target\classes [INFO] ------------------------------------------------------------------------ [ERROR] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.15.0:compile (default-compile) on project shoplite-api: Fatal error compiling: error: release version 21 not supported -> [Help 1]
What this code does
- This run had JDK 19, and the pom asked for Java 21, so
javacrefused:release version 21 not supported. With JDK 11 and ShopLite's Java 17 pom, the same line ends inrelease version 17 not supported. - Fix the JDK, not the pom: install JDK 17 or newer, set
JAVA_HOME, open a new terminal and check withmvnw -v. Loweringjava.versionbelow 17 does not work, because Spring Boot 4 itself needs Java 17.
Example 5 · Port 8080 already in use
Runs in: the shoplite-api Spring Boot project
mvnw spring-boot:run. ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v4.1.1) 2026-10-16T08:31:19.569+05:30 INFO 36032 --- [shoplite-api] [ main] com.shoplite.ShopliteApiApplication : Starting ShopliteApiApplication using Java 19.0.2 with PID 36032 (C:\Users\asha\shoplite-api\target\classes started by asha in C:\Users\asha\shoplite-api) 2026-10-16T08:31:19.580+05:30 INFO 36032 --- [shoplite-api] [ main] com.shoplite.ShopliteApiApplication : No active profile set, falling back to 1 default profile: "default" 2026-10-16T08:31:22.067+05:30 INFO 36032 --- [shoplite-api] [ main] o.s.boot.tomcat.TomcatWebServer : Tomcat initialized with port 8080 (http) 2026-10-16T08:31:22.133+05:30 INFO 36032 --- [shoplite-api] [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat] 2026-10-16T08:31:22.134+05:30 INFO 36032 --- [shoplite-api] [ main] o.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/11.0.24] 2026-10-16T08:31:22.519+05:30 INFO 36032 --- [shoplite-api] [ main] b.w.c.s.WebApplicationContextInitializer : Root WebApplicationContext: initialization completed in 2746 ms 2026-10-16T08:31:23.679+05:30 WARN 36032 --- [shoplite-api] [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Failed to start bean 'webServerStartStop' 2026-10-16T08:31:23.820+05:30 INFO 36032 --- [shoplite-api] [ main] .s.b.a.l.ConditionEvaluationReportLogger : Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled. 2026-10-16T08:31:23.877+05:30 ERROR 36032 --- [shoplite-api] [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPLICATION FAILED TO START *************************** Description: Web server failed to start. Port 8080 was already in use. Action: Identify and stop the process that's listening on port 8080 or configure this application to listen on another port.
What this code does
- Tomcat was set up for 8080 but could not open it, so Boot stopped the app. Ignore the long
WARNline; the Description and Action at the bottom say what to do. - Maven then prints
BUILD FAILUREbecause the app exited with code 1. Nothing is wrong with your code.
Example 6 · Finding and stopping the program on port 8080 (Windows)
Runs in: a Windows terminal
netstat -ano | findstr :8080 | findstr LISTENINGtaskkill /PID 6460 /F> netstat -ano | findstr :8080 | findstr LISTENING TCP 0.0.0.0:8080 0.0.0.0:0 LISTENING 6460 TCP [::]:8080 [::]:0 LISTENING 6460 > taskkill /PID 6460 /F SUCCESS: The process with PID 6460 has been terminated.
What this code does
netstat -anolists open ports with the owning process id; the twofindstrfilters keep port 8080 lines in theLISTENINGstate. The last column, 6460, is the PID.taskkill /PID 6460 /Fstops that process; here it was an old ShopLite run left open in another terminal. On macOS,lsof -i :8080andkill 6460do the same.
Wrong JDK: the project asks for Java 17 (<java.version>17</java.version>), but Maven runs with an older JDK, so the compiler fails with release version 17 not supported. Run mvnw -v to see which Java Maven uses, then install JDK 17 or newer and point JAVA_HOME at it (the Getting Started module showed how). Read the bottom of any failed run first: Boot prints a short Description and Action block for many startup problems, and Maven's last [ERROR] lines name the step that failed.
Port in use: an earlier run of the same app you forgot to stop often still listens on 8080, and Boot stops with Port 8080 was already in use. Find the program with netstat -ano | findstr :8080 on Windows (the last number is its process id) or lsof -i :8080 on macOS, stop it with taskkill /PID <pid> /F or kill <pid>, or run ShopLite on another port:
- For one run:
.\mvnw spring-boot:run "-Dspring-boot.run.arguments=--server.port=8081"in PowerShell (the quotes are needed), or./mvnw spring-boot:run -Dspring-boot.run.arguments=--server.port=8081on macOS. - For good: add
server.port=8081tosrc/main/resources/application.properties.
Predict the output
Read the startup failure
Read each failure message and pick the most likely cause.
Round 1 of 2
The app stops right after Tomcat starts.
java. If 8080 belongs to another tool you need, change ShopLite's port instead.Next step
Check your understanding
12 quick questions