Spring Boot Tutorial
Spring Boot - Software Setup and Configuration (STS/Eclipse/IntelliJ)
Prerequisite (Spring Core Concepts)
Spring Boot Core
Spring Boot with REST API
Spring Boot with Database and Data JPA
Spring Boot with Kafka
Spring Boot with AOP
Spring Boot provides a way to simplify the bootstrapping and development of new Spring applications. One of its core components is the use of "starters" - templates that provide a set of default configurations, dependencies, and behaviors. Among these starters, there's the spring-boot-starter-parent
.
The spring-boot-starter-parent
is a special starter that provides useful Maven defaults. It also includes the spring-boot-dependencies
BOM (Bill Of Materials). Here's why you might want to use it:
Dependency Management: The parent POM (Project Object Model) provides a centralized place for defining common dependencies so you don't have to specify version numbers for any of the common Spring Boot dependencies.
Default Plugin Configurations: It provides default configurations for Maven plugins, for instance, the maven-failsafe-plugin
and the maven-jar-plugin
.
Inherits Java Version and other properties: It provides a Java version property which is used to set the Java version in the project.
Resource Filtering: It provides resource filtering for application properties and YAML files, which is useful for various profiles you might have like dev, test, prod, etc.
UTF-8 Source Encoding: It sets the source code encoding default to UTF-8.
Using the spring-boot-starter-parent
is as simple as setting it as your project's parent in your Maven pom.xml
:
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.X.X.RELEASE</version> </parent>
Replace 2.X.X.RELEASE
with the version of Spring Boot you want to use.
However, if you need custom parent POM configurations, or if your organization already uses a corporate-wide parent POM, it might be tricky to incorporate the spring-boot-starter-parent
. In such cases, you can still leverage the dependency management capabilities of Spring Boot without using the starter-parent
directly, by importing the spring-boot-dependencies
BOM in the dependencyManagement
section of your POM.
In conclusion, the spring-boot-starter-parent
provides a hassle-free way of setting up a Spring Boot project with Maven by offering sensible defaults, but like all defaults in the Spring ecosystem, they're just recommendations and can be overridden or bypassed if your specific case requires it.
Configuring projects with Spring Boot Starter Parent:
spring-boot-starter-parent
is a special starter POM that provides default configurations and settings for Spring Boot projects. It manages common build settings, dependencies, and plugin configurations.<!-- Example using Spring Boot Starter Parent in your project's POM --> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.6.4</version> <!-- Use the latest version --> </parent>
Inheritance and version management with Starter Parent in Spring Boot:
spring-boot-starter-parent
benefit from version management. Spring Boot manages versions of dependencies, plugins, and other settings, ensuring compatibility.<!-- Example version management with Spring Boot Starter Parent --> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <!-- Other dependencies with managed versions --> </dependencies>
Overriding properties and dependencies in Spring Boot Starter Parent:
spring-boot-starter-parent
.<!-- Example overriding properties in Spring Boot Starter Parent --> <properties> <java.version>11</java.version> <!-- Other overridden properties --> </properties>
Customizing build settings with Starter Parent in Spring Boot:
spring-boot-starter-parent
.<!-- Example customizing build settings in Spring Boot Starter Parent --> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <!-- Custom configurations for the plugin --> </plugin> <!-- Other plugins --> </plugins> </build>
Managing dependencies and plugins with Spring Boot Starter Parent:
spring-boot-starter-parent
manages dependencies and plugins, simplifying project configuration. Use starters to easily include sets of dependencies.<!-- Example managing dependencies with Spring Boot Starter Parent --> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> <!-- Other dependencies managed by the parent --> </dependencies>
Parent POM vs. Starter Parent in Spring Boot:
spring-boot-starter-parent
can be used, the latter is specifically designed for Spring Boot projects. It provides conventions and defaults tailored for Spring Boot applications.<!-- Example using a custom parent POM --> <parent> <groupId>com.example</groupId> <artifactId>my-parent</artifactId> <version>1.0.0</version> </parent>
Extending and creating custom starters with Starter Parent in Spring Boot:
spring-boot-starter-parent
. This allows you to define a set of dependencies and configurations for reuse across projects.<!-- Example custom starter with Spring Boot Starter Parent --> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> <!-- Other common dependencies --> </dependencies>
Updating to the latest version of Spring Boot Starter Parent:
spring-boot-starter-parent
in your project to benefit from the latest features, bug fixes, and dependency updates.<!-- Example updating to the latest version of Spring Boot Starter Parent --> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.7.0</version> <!-- Use the latest version --> </parent>