Advantages of Spring Boot and Spring Boot Installation

Spring Boot is developed by Pivotal Team with the aim of creating a production-ready spring application quickly. This tutorial gives you an overview of the features of Spring boot and its advantages in the development life cycle. We will discuss the advantages of spring boot and spring boot installation in this tutorial.

Advantages of Spring Boot

  1. Spring boot uses the foundation of spring framework itself which is widely popular.
  2. It thus empowers the Spring developer to reduce the development effort.
  3. It intends to create a production-ready application as quickly as possible and simplifies development of a Spring boot application.
  4. Thus, it reduces the complexity that the developer would face when configuring a spring application.
  5. With Spring boot, the developer can focus more on business goals and less on setup.

[wp-sociallocker id=”20988″]

Spring Boot Features

  1. Spring Boot decides the standard set of dependencies to download, thereby preventing version conflicts.
  2. It helps to set up a production-ready application very quickly by providing default configurations.
  3. The powerful capabilities of the Spring ecosystem are automatically enabled in your application through a few dependencies in your CLASSPATH using auto-configuration.
  4. Adding such dependencies via Maven/Gradle is very easy and fast.
  5. The developer has the flexibility to override the default configuration which the spring boot provides.
  6. In other words, Spring boot auto-configuration gives priority to your own defined configuration and backs off in case you have defined your configuration through beans.
  7. It provides support for Starters which provides pre-defined dependency JARS as well as Actuators that provides support for Monitoring the production applications.
  8. Don’t worry about the usage of Actuators and Starters. More details on these concepts are explained in the following tutorials.
  9. It provides a CLI tool feature. More details about CLI is in the later part of this tutorial.
  10. Like Spring application, there is no need for XML configuration.
  11. Supports deploying as JAR as well as WAR in an embedded servlet container like Tomcat, Jetty, Undertow etc.

Below diagram gives you an overview of Spring boot framework and its corresponding modules:

Spring boot Framework Architecture

Environment Support Matrix

The following are the environment pre-requisite matrix supported by Spring boot 2.1.3.RELEASE.

SPRING BOOT 2.1.3.RELEASE

Java

8 to 11

Spring Framework

5.1.5.RELEASE or above

Build Tool

3.3+

Servlet Container

3.1+ compatible container

 

Spring Boot Installation

  • Spring boot JAR (spring-boot-*.jar) files can be copied into the classpath as any standard Java library, and no other particular configuration or integration is needed.
  • However, Spring Boot generally recommends using a dependency management build tool like Maven, etc. which downloads the dependencies automatically.
  • The following sections explain the process involved while using Maven dependency tool

Installation using Maven

  • If you do not have Maven version 3.3 or above already installed, so you can follow the instructions and download as specified in maven.apache.org
  • After successful installation, add the following lines of code in maven pom.xml to download the spring boot dependencies as follows:
<!-- Inherit defaults from Spring Boot -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.3.RELEASE</version>
</parent>

<!-- Add typical dependencies for a web application -->
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>

<!-- Package as an executable jar -->
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

We have discussed advantages of spring boot and spring boot installation, now we will mention about how to use the command line interface to play with spring boot.

Spring Boot CLI Tool

  • The Spring Boot CLI (Command Line Interface) is an optional tool. However, it is a quick way to start playing around with Spring.
  • It allows running groovy scripts, just like java code without many complex configurations.
  • Spring CLI requires Java 1.8 or above. As a part of this distribution, Groovy is also packaged.
  • Spring CLI distribution can be downloaded from the Spring software repository:

After downloaded, please follow the instructions from the unpackaged archive of INSTALL.txt.

Running code from CLI

The following section gives you an overview to run the Spring boot applications using CLI. For instance, the following is a sample groovy script:

@RestController
class WebApplication {

@RequestMapping("/")
String home() {
"Hello World!"
}
}
  • Type the following command to run the above application and hit enter:
$ spring run hello.groovy
  • Command line arguments can be passed to the application as follows. Below is an example of running the application on the server port: 9000
$ spring run hello.groovy -- --server.port=9000

Other Features of CLI

The following are few of the advantages of using CLI along with groovy code:

[vc_row][vc_column width=”2/3″][td_block_text_with_title custom_title=”Deduced Grab dependencies”][/td_block_text_with_title][/vc_column][/vc_row]

Standard Groovy syntax supports the use of @Grab annotation that lets you declare dependencies on a third party library and make it available on the CLASSPATH.

An example below:

@Grab(group='commons-lang', module='commons-lang', version='3.4')
import org.apache.commons.lang.WordUtils
println "Hello ${WordUtils.capitalize('world')}"

[vc_row][vc_column width=”2/3″][td_block_text_with_title custom_title=”Deduced Grab coordinates”][/td_block_text_with_title][/vc_column][/vc_row]

Spring Boot extends Groovy’s standard @Grab support by letting you specify a dependency without a group or version (for example, @Grab(‘freemarker‘)). Doing so consults the default dependency metadata of Spring Boot to deduce the group and version of the artifact.

[vc_row][vc_column width=”2/3″][td_block_text_with_title custom_title=”No import statements”][/td_block_text_with_title][/vc_column][/vc_row]

Apart from the above, there is no need to include the import statements in the groovy code explicitly, and you can mention the annotations as follows:

Example: @RestController , @RequestMapping etc.

[vc_row][vc_column width=”2/3″][td_block_text_with_title custom_title=”No Main Class”][/td_block_text_with_title][/vc_column][/vc_row]

No need to include the main method in the groovy script as SpringApplication is automatically created.

[vc_row][vc_column width=”2/3″][td_block_text_with_title custom_title=”Packaging the application”][/td_block_text_with_title][/vc_column][/vc_row]

To package your application into a self-executable JAR file, run the following command:

$ spring jar myFirstApp.jar *.groovy

The JAR that got created contains all the classes generated by the compiled application as well as its dependencies & entries in CLASSPATH.

This JAR can be deployed using:

java -jar myFirstApp.jar

[vc_row][vc_column width=”2/3″][td_block_text_with_title custom_title=”Conclusion”][/td_block_text_with_title][/vc_column][/vc_row]

As part of this tutorial, you have learned the basics of Spring boot and its essential features, the advantage of Spring boot CLI, as well as the Installation procedure. This tutorial was basically for advantages of spring boot and spring boot installation, in the following tutorials, you can understand setting up a running Spring boot application from scratch.

[vc_row][vc_column width=”2/3″][td_block_text_with_title custom_title=”References”][/td_block_text_with_title][/vc_column][/vc_row]

Refer the below links from the official spring boot documentation:

[/wp-sociallocker]

Translate »