POM.xml helps manage your project settings and libraries in one place. Dependencies tell your project which extra tools it needs to work.
0
0
POM.xml and dependencies in Spring Boot
Introduction
When starting a new Spring Boot project to set up basic configurations.
When adding a new library like a database driver or web framework to your project.
When updating versions of tools your project uses to get new features or fixes.
When sharing your project with others so they get the same setup automatically.
Syntax
Spring Boot
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.example</groupId> <artifactId>myapp</artifactId> <version>1.0.0</version> <dependencies> <dependency> <groupId>group.name</groupId> <artifactId>library-name</artifactId> <version>1.2.3</version> </dependency> </dependencies> </project>
The groupId, artifactId, and version uniquely identify your project.
Each dependency block tells Maven which library to download and use.
Examples
Adds Spring Boot's web tools to your project for building web apps.
Spring Boot
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>3.0.0</version>
</dependency>Adds database access tools. Version can be omitted if managed by Spring Boot parent.
Spring Boot
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>Adds H2 database only for running the app, not for compiling.
Spring Boot
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>Sample Program
This POM.xml sets up a Spring Boot web app with testing tools. The parent manages versions so you don't have to specify them.
Spring Boot
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>3.0.0</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.example</groupId> <artifactId>demoapp</artifactId> <version>0.1.0</version> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies> </project>
OutputSuccess
Important Notes
Always use the Spring Boot starter parent to simplify version management.
Dependencies inside <dependencies> tell Maven what libraries to include.
Scopes like test or runtime control when the dependency is used.
Summary
POM.xml organizes your project and its libraries in one file.
Dependencies list the extra tools your project needs.
Using Spring Boot starter parent helps manage versions easily.