Spring Boot Overview
Spring Boot is maintained by VMware.
Before understanding Spring Boot, it helps to know how Java evolved.
- Java (Java SE) = The programming language and the basic platform.
- Java EE = Java along with Enterprise APIs.
- Jakarta EE = The modern continuation of Java EE.
The Spring Framework is the core framework, whereas Spring Boot is an opinionated layer built on top of the Spring Framework. It automatically configures many components, manages dependencies, provides embedded servers, and makes it much easier to build and run Spring applications.
Spring itself is built on top of Java and frequently relies on Jakarta EE specifications internally.
Internally, Spring Boot uses:
-
jakarta.servletfor handling HTTP requests. -
jakarta.persistencefor JPA entities. -
jakarta.validationfor Bean Validation.
Rather than requiring developers to work directly with Jakarta APIs, Spring provides its own programming model using annotations such as:
@RestController@Autowired
It also offers Spring Data JPA while internally using Jakarta technologies.
What is Maven?
Maven is primarily a project management and build automation tool. It helps manage:
- Builds
- Dependencies
- Documentation
- Software Configuration Management (SCM)
- Releases
- Reporting
- Distribution
Maven improves the build process by following standard conventions and best practices, helping teams develop faster while increasing the chances of successful builds.
Artifact and Resolution
Artifact
In Maven, an artifact is anything that Maven either produces or downloads.
Resolution
Resolution refers to the process of locating and downloading project dependencies.
Maven Configuration Levels
Maven configuration exists at three different levels.
Project Level
Most of the static configuration is stored inside the pom.xml file.
Static configuration means the settings are common for everyone working on the project.
Installation Level
Configuration that is applied once for a Maven installation.
User Level
Configuration specific to an individual user.
Configuration file:
${user.home}/.m2/settings.xml
Maven Repositories
Maven works with three types of repositories.
- Local Repository (stored on your computer)
- Central Repository (available on the Internet)
- Remote Repository (maintained by a company or organization)
A repository is simply a folder where Maven stores downloaded dependencies and generated artifacts.
The default Local Repository location is:
${user.home}/.m2/repository/
Proxy Server
Normally, when downloading a file, your computer sends the request directly to the website.
However, many companies do not allow employees to access the Internet directly. Instead, every request must pass through a proxy server.
A proxy server acts as a middleman between your computer and the Internet.
Companies use proxy servers for:
- Security
- Monitoring
- Access Control
- Caching
Maven Proxy Configuration
Sometimes Maven displays errors such as:
- "Could not transfer artifact"
- "Connection timed out"
These usually indicate that the company network uses a proxy server which blocks Maven from downloading dependencies.
To solve this, configure the proxy in Maven.
Edit:
${user.home}/.m2/settings.xml
Inside this file, configure the proxy using fields like:
- id
- active
- protocol
- host (hostname)
- port
- username
- password
Configure Parallel Artifact Resolution
By default, Maven downloads up to five artifacts (from different groups) simultaneously.
To change the thread pool size temporarily:
mvn -Dmaven.artifact.threads=1 verify
For a permanent configuration, use the MAVEN_OPTS environment variable.
export MAVEN_OPTS=-Dmaven.artifact.threads=3
Maven Archetype
An Archetype is Maven's project templating toolkit.
A Maven Archetype is a predefined project template used to generate the initial structure of a Maven project.
Start the interactive wizard using:
mvn archetype:generate
The wizard asks for values such as:
- Archetype
- GroupId
- ArtifactId
- Version
- Package Name
A non-interactive example:
mvn archetype:generate \
-DgroupId=com.example \
-DartifactId=my-app \
-DarchetypeArtifactId=maven-archetype-quickstart \
-DarchetypeGroupId=org.apache.maven.archetypes \
-DarchetypeVersion=1.5 \
-DinteractiveMode=false
Here, -D means Define a system property.
For example, -DgroupId=com.example creates the system property named groupId with the value com.example.
The generated project structure looks like:
my-app/
├── pom.xml
└── src
├── main
│ └── java
│ └── com/example/App.java
└── test
└── java
└── com/example/AppTest.java
Common Maven Archetypes
| Archetype | Purpose |
|---|---|
maven-archetype-quickstart |
Simple Java Application |
maven-archetype-webapp |
Java Web Application |
maven-archetype-simple |
Basic Maven Project |
Create Your Own Maven Archetype
Convert an existing project into an Archetype using:
mvn archetype:create-from-project
Then install the generated Archetype.
cd target/generated-sources/archetype
mvn install
What is MVN?
mvn is not a Java class.
It is a shell script on Linux/macOS and a batch file (mvn.cmd) on Windows.
Its responsibility is to start the Maven Java application.
Launching Maven Archetype
Step 1 – Execute mvn
The mvn script (or mvn.cmd on Windows):
- Finds the Java installation.
- Sets the required environment variables.
- Launches the Maven Java program.
At this point, one Java application starts: Maven itself.
Step 2 – Maven Starts
The JVM loads the Maven CLI class org.apache.maven.cli.MavenCli.
This is the main Java application responsible for Maven execution.
Step 3 – Maven Parses the Command
For example:
- Plugin:
archetype - Goal:
generate
Step 4 – Maven Loads the Archetype Plugin
If the plugin is not already available in the local repository, Maven downloads it.
After downloading, Maven loads the plugin classes into the same JVM where the Maven CLI is already running.
Step 5 – Maven Calls the Plugin
The plugin receives all the supplied values and generates the project.
Flow of mvn spring-boot:run
mvn spring-boot:run
│
▼
Shell Script (mvn)
│
▼
Starts JVM #1
│
▼
MavenCli
│
▼
Reads pom.xml
│
▼
Loads Spring Boot Maven Plugin
│
▼
Compiles the Project
│
▼
Starts JVM #2
│
▼
DemoApplication.main()
│
▼
SpringApplication.run()
│
▼
Embedded Tomcat Starts
When running mvn spring-boot:run, two JVMs are usually involved.
Why Doesn't Maven Run the Application in the Same JVM?
Maven is a build tool, whereas the application is the software being built.
Keeping them separate provides several advantages.
- If the application crashes, Maven continues running.
- The application's classpath remains isolated from Maven's classpath.
- The application can be stopped and restarted independently.
Commands and Number of JVMs
| Command | JVMs |
|---|---|
mvn compile |
Usually 1 (Maven only) |
mvn archetype:generate |
1 (Maven + Archetype Plugin in the same JVM) |
mvn spring-boot:run |
Usually 2 (Maven + Spring Boot Application) |
mvn test |
Usually 2 (Maven + Test JVM) |
java -jar app.jar |
1 (Application only) |
Where:
- JVM #1 = Maven itself.
- JVM #2 = Spring Boot application.
pom.xml
The pom.xml file contains the Project Object Model (POM) for a project.
The POM is the fundamental unit of Maven.
It is important to remember that Maven is project-centric, meaning everything revolves around the concept of a project.
The POM contains every important piece of information related to the project.
What's Next?
Tomorrow we will go through the complete details of pom.xml in depth.
Top comments (0)