Chapter 2. Configuring your application to use Spring Boot
Configure your application to use dependencies provided with Red Hat build of Spring Boot. By using the BOM to manage your dependencies, you ensure that your applications always uses the product version of these dependencies that Red Hat provides support for. Reference the Spring Boot BOM (Bill of Materials) artifact in the pom.xml
file at the root directory of your application. You can use the BOM in your application project in 2 different ways:
-
As a dependency in the
<dependencyManagement>
section of thepom.xml
. When using the BOM as a dependency, your project inherits the version settings for all Spring Boot dependencies from the<dependencyManagement>
section of the BOM. As a parent BOM in the
<parent>
section of thepom.xml
. When using the BOM as a parent, thepom.xml
of your project inherits the following configuration values from the parent BOM:-
versions of all Spring Boot dependencies in the
<dependencyManagement>
section -
versions plugins in the
<pluginManagement>
section -
the URLs and names of repositories in the
<repositories>
section -
the URLs and name of the repository that contains the Spring Boot plugin in the
<pluginRepositories>
section
-
versions of all Spring Boot dependencies in the
2.1. Prerequisites
-
A Maven-based application project that you configure using a
pom.xml
file. - Access to the Red Hat JBoss Middleware General Availability Maven Repository.
2.2. Using the Spring Boot BOM to manage dependency versions
Manage versions of Spring Boot product dependencies in your application project using the product BOM.
Procedure
Add the
dev.snowdrop:snowdrop-dependencies
artifact to the<dependencyManagement>
section of thepom.xml
of your project, and specify the values of the<type>
and<scope>
attributes:<project> ... <dependencyManagement> <dependencies> <dependency> <groupId>dev.snowdrop</groupId> <artifactId>snowdrop-dependencies</artifactId> <version>2.2.11.SP1-redhat-00001</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> ... </project>
Include the following properties to track the version of the Spring Boot Maven Plugin that you are using:
<project> ... <properties> <spring-boot-maven-plugin.version>2.2.11.RELEASE</spring-boot-maven-plugin.version> </properties> ... </project>
Specify the names and URLs of repositories containing the BOM and the supported Spring Boot Starters and the Spring Boot Maven plugin:
<!-- Specify the repositories containing Spring Boot artifacts. --> <repositories> <repository> <id>redhat-ga</id> <name>Red Hat GA Repository</name> <url>https://maven.repository.redhat.com/ga/</url> </repository> </repositories> <!-- Specify the repositories containing the plugins used to execute the build of your application. --> <pluginRepositories> <pluginRepository> <id>redhat-ga</id> <name>Red Hat GA Repository</name> <url>https://maven.repository.redhat.com/ga/</url> </pluginRepository> </pluginRepositories>
Add
spring-boot-maven-plugin
as the plugin that Maven uses to package your application.<project> ... <build> ... <plugins> ... <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <version>${spring-boot-maven-plugin.version}</version> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> <configuration> <redeploy>true</redeploy> </configuration> </plugin> ... </plugins> ... </build> ... </project>
2.3. Using the Spring Boot BOM to as a parent BOM of your application
Automatically manage the:
- versions of product dependencies
- version of the Spring Boot Maven plugin
- configuration of Maven repositories containing the product artifacts and plugins
that you use in your application project by including the product Spring Boot BOM as a parent BOM of your project. This method provides an alternative to using the BOM as a dependency of your application.
Procedure
Add the
dev.snowdrop:snowdrop-dependencies
artifact to the<parent>
section of thepom.xml
:<project> ... <parent> <groupId>dev.snowdrop</groupId> <artifactId>snowdrop-dependencies</artifactId> <version>2.2.11.SP1-redhat-00001</version> </parent> ... </project>
Add
spring-boot-maven-plugin
as the plugin that Maven uses to package your application to the<build>
section of thepom.xml
. The plugin version is automatically managed by the parent BOM.<project> ... <build> ... <plugins> ... <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> <configuration> <redeploy>true</redeploy> </configuration> </plugin> ... </plugins> ... </build> ... </project>