Programming & Development / April 12, 2025

Spring Boot Web Dependency Maven Example

Spring Boot Maven spring-boot-starter-web web dependency pom.xml Maven configuration Spring Boot setup Maven project Spring Web dependency Spring Boot application

When building a Spring Boot application with Maven, one of the core dependencies you need to include is the spring-boot-starter-web. This starter package provides all the necessary libraries to build web applications, including support for RESTful web services. In this guide, we will show you how to include the Spring Boot Web dependency in your Maven pom.xml file.

Step-by-Step Guide to Adding the Spring Boot Web Dependency in Maven

1. Edit your pom.xml File

To include the Spring Boot Web dependency, you need to add the following dependency entry into the <dependencies> section of your Maven pom.xml file:

xml

<dependencies>
    <!-- Other dependencies -->

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
</dependencies>

2. Complete Example of pom.xml

Here is a complete example of a pom.xml file that includes the Spring Boot Web dependency:

xml

<?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>

    <groupId>com.example</groupId>
    <artifactId>my-spring-boot-app</artifactId>
    <version>1.0.0</version>

    <properties>
        <java.version>11</java.version>
        <spring-boot.version>2.5.2</spring-boot.version>
    </properties>

    <dependencies>
        <!-- Other dependencies -->

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <!-- Maven plugins -->
        </plugins>
    </build>
</project>

3. Explanation of the pom.xml Configuration

  • GroupId and ArtifactId: Replace com.example with your desired group name and my-spring-boot-app with the name of your project.
  • Spring Boot Version: The version of Spring Boot you use can be specified in the <properties> section. In this example, 2.5.2 is used. Make sure to adjust it to the version that fits your project requirements.
  • Java Version: This configuration specifies that the project uses Java 11. You can modify this based on your environment.
  • Spring Boot Starter Web: The <dependency> for spring-boot-starter-web is the core part. It includes dependencies for Spring MVC, embedded Tomcat server, and other essential components for creating web applications.

4. Building and Running Your Application

After adding the dependency to your pom.xml, you can proceed to build your Spring Boot application by running Maven commands. Maven will automatically download all the necessary dependencies, including the Spring Web libraries, for you.

To build and run the application, execute the following Maven commands in your terminal:

  • Build the application:
bash

mvn clean install
  • Run the application:
bash

mvn spring-boot:run

Your Spring Boot application should now be up and running with the necessary web components provided by the spring-boot-starter-web dependency.

Conclusion

By adding the spring-boot-starter-web dependency to your Maven pom.xml, you've equipped your Spring Boot project with everything needed to develop a web-based application. This includes support for creating RESTful APIs, integrating with front-end frameworks, and embedding a web server like Tomcat.


Comments

No comments yet

Add a new Comment

NUHMAN.COM

Information Technology website for Programming & Development, Web Design & UX/UI, Startups & Innovation, Gadgets & Consumer Tech, Cloud Computing & Enterprise Tech, Cybersecurity, Artificial Intelligence (AI) & Machine Learning (ML), Gaming Technology, Mobile Development, Tech News & Trends, Open Source & Linux, Data Science & Analytics

Categories

Tags

©{" "} Nuhmans.com . All Rights Reserved. Designed by{" "} HTML Codex