Building an Application with Spring Boot

To launch Spring Boot Application developer needs to do the following :

  1. Add dependencies provided by Spring Boot to a project. This can be done in two ways:
  • using spring-boot-starter-parent as a parent project (if a project does not have a parent):
                <parent>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-parent</artifactId>
			<version>(version number)</version>
		</parent>
  • using dependencyManagement:
                <dependencyManagement>
                   <dependencies>
                      <dependency>
                         <groupId>org.springframework.boot</groupId>
                         <artifactId>spring-boot-dependencies</artifactId>
                         <version>1.3.3.RELEASE</version>
                         <scope>import</scope>
                         <type>pom</type>
                      </dependency>
                   </dependencies>
                </dependencyManagement>

Second approach is more profitable because it solves all issues with versions discrepancies provided by Spring Boot. Different starters of the same Spring Boot version can refer to different versions of the same dependency, and it can cause unexpected and unobvious mistakes.

2. Use maven plugin provided by Spring Boot for building project

  • using parent project:

 

                <plugin>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>
  • using dependencyManagement:
                 <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                    <executions>
                       <execution>
                          <goals>
                             <goal>repackage</goal>
                          </goals>
                       </execution>
                    </executions>
                 </plugin>

This plugin will find a class containing method public static void main, mark it as main class, assemble executable jar or war and copy all dependencies in it.

3. Add dependency for at least one of starters (spring-boot-starter). Spring Boot provides large number of starters for different cases. Actually, starter is a dependency, containing all dependencies necessary for implementing any functionality in application.

Next

Leave a Reply

Your email address will not be published. Required fields are marked *