By WebNest Studio Engineering Team
Spring Framework Tutorial
Setting Up a Spring Project
A plain Spring Framework project (without Spring Boot) needs only a JDK, a build tool and one dependency: spring-context. This is the best way to learn the container itself, because nothing is hidden behind auto-configuration. In this lesson you will create a Maven project by hand, understand every line of its pom.xml, see the folder structure, and compile it.
The next lessons then show how Spring Initializr creates a full Spring Boot project in seconds, and how to run your first application in both styles.
What you need first
Install a JDK 17 or newer (see the JDK installation lesson) and confirm that java -version and javac -version work. Then choose Maven or Gradle. The rest of this lesson uses Maven, and the Maven wrapper or a locally installed Maven both work.
The standard folder structure
Maven and Gradle expect the same layout, so learn it once. Java code goes under src/main/java, resources such as properties files go under src/main/resources, and tests go under src/test/java. Your packages then follow the reverse-domain convention.
pom.xml- the Maven build description at the project root.src/main/java/com/webnest/first- your application classes.src/main/resources- configuration files, templates and static files.src/test/java- unit and integration tests.target- build output, created by Maven. Never commit it to Git.
The pom.xml, line by line
The groupId, artifactId and version identify your project. The maven.compiler.release property tells the compiler which Java version to target, and it must not be higher than your installed JDK. The spring.version property keeps the Spring version in one place. The single dependency, org.springframework:spring-context, brings in the container and, transitively, spring-core, spring-beans, spring-aop and spring-expression. You never list those individually.
Why Spring Boot changes the pom
In a Spring Boot project you do not write a Spring version at all. Instead the pom declares spring-boot-starter-parent as its parent, which manages compatible versions for hundreds of libraries, and you add starters such as spring-boot-starter-webmvc. In Spring Boot 4 the web starter is named spring-boot-starter-webmvc (older tutorials call it spring-boot-starter-web), and each starter has a matching -test starter for its tests.
Compile to confirm the setup
Once the files exist, run mvn compile (or ./mvnw compile if you copied a wrapper). The first run downloads Spring and Maven plugins, which can take a minute. A successful build ends with BUILD SUCCESS. If you see an error about the release version, your JDK is older than maven.compiler.release.
Examples
A complete pom.xml for a plain Spring Framework 7.0 application (verified to build)
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.webnest</groupId>
<artifactId>first-spring</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>
<properties>
<maven.compiler.release>17</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spring.version>7.0.9</spring.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
</dependencies>
</project>
The same dependency in a Gradle build (Kotlin DSL)
plugins {
java
}
java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
}
}
repositories {
mavenCentral()
}
dependencies {
implementation("org.springframework:spring-context:7.0.9")
}
Common Mistakes
- Putting Java files directly in the project root or in src/main instead of src/main/java, so the compiler ignores them.
- Setting maven.compiler.release higher than the JDK you installed.
- Adding several Spring versions manually. Use one spring.version property, or let Spring Boot manage versions.
- Copying a Spring 5 or 6 tutorial that imports javax.* classes; current Spring uses jakarta.* for servlet, validation and persistence APIs.
Exercise
Using the lesson's A complete pom.xml for a plain Spring Framework 7.0 application (verified to build) example, create a small implementation or design sketch that demonstrates A plain Spring project needs a JDK, a build tool and the spring-context dependency.. Add a test case or scenario that would catch Putting Java files directly in the project root or in src/main instead of src/main/java, so the compiler ignores them., and describe the expected result.
Show hints
- Start with What you need first and compare your approach with A complete pom.xml for a plain Spring Framework 7.0 application (verified to build). Identify the decision or behavior the lesson recommends.
- Walk through your scenario step by step. Confirm that it follows A plain Spring project needs a JDK, a build tool and the spring-context dependency. and that it would catch the failure described by Putting Java files directly in the project root or in src/main instead of src/main/java, so the compiler ignores them..
Quick quiz
1. Which choice is a mistake to avoid in Setting Up a Spring Project?
- A. Setting maven.compiler.release higher than the JDK you installed.
- B. A plain Spring project needs a JDK, a build tool and the spring-context dependency.
- C. Putting Java files directly in the project root or in src/main instead of src/main/java, so the compiler ignores them.
Show answer
C. Avoid this approach: Putting Java files directly in the project root or in src/main instead of src/main/java, so the compiler ignores them. The lesson recommends: A plain Spring project needs a JDK, a build tool and the spring-context dependency.
Interview questions
A teammate is about to make this mistake: Putting Java files directly in the project root or in src/main instead of src/main/java, so the compiler ignores them. How would you diagnose and correct it using the lesson's guidance?
Show answer
A plain Spring project needs a JDK, a build tool and the spring-context dependency. Apply this in What you need first; the example A complete pom.xml for a plain Spring Framework 7.0 application (verified to build) shows one way to do it. Avoid Putting Java files directly in the project root or in src/main instead of src/main/java, so the compiler ignores them. and explain how your implementation or design prevents that failure.
Key Points to Remember
- A plain Spring project needs a JDK, a build tool and the spring-context dependency.
- Maven and Gradle share the src/main/java, src/main/resources and src/test/java layout.
- Spring Boot replaces the version handling with spring-boot-starter-parent and starters.
- In Spring Boot 4 the web starter is spring-boot-starter-webmvc.
Practice in the playground
Write and run your own code for this topic, or start from the exercise or an example. Runs plain Java 17. Frameworks such as Spring, and databases, are not available here. Your code for each topic is kept in this browser.
Run the examples
Change an input, predict the result, then compare it with the output. Explain why the result changes.
These examples need a JDK project with their libraries on your computer, so they can be copied but not run here. Codelab runs Python, FastAPI backends with SQLite, plain Java 17 and HTML/CSS/JavaScript.
Written by
WebNest Studio Engineering Team
Practical lessons from developers working with Java, Python, React, databases and production systems.
Led by Vansh Duggal, Founder, WebNest Studio · Full-stack & software engineering