Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Spring Boot 2.0 Cookbook
  • Toc
  • feedback
Spring Boot 2.0 Cookbook

Spring Boot 2.0 Cookbook

By : Antonov
2 (3)
close
Spring Boot 2.0 Cookbook

Spring Boot 2.0 Cookbook

2 (3)
By: Antonov

Overview of this book

The Spring framework provides great flexibility for Java development, which also results in tedious configuration work. Spring Boot addresses the configuration difficulties of Spring and makes it easy to create standalone, production-grade Spring-based applications. This practical guide makes the existing development process more efficient. Spring Boot Cookbook 2.0 Second Edition smartly combines all the skills and expertise to efficiently develop, test, deploy, and monitor applications using Spring Boot on premise and in the cloud. We start with an overview of the important Spring Boot features you will learn to create a web application for a RESTful service. Learn to fine-tune the behavior of a web application by learning about custom routes and asset paths and how to modify routing patterns. Address the requirements of a complex enterprise application and cover the creation of custom Spring Boot starters. This book also includes examples of the new and improved facilities available to create various kinds of tests introduced in Spring Boot 1.4 and 2.0, and gain insights into Spring Boot DevTools. Explore the basics of Spring Boot Cloud modules and various Cloud starters to make applications in “Cloud Native” and take advantage of Service Discovery and Circuit Breakers.
Table of Contents (11 chapters)
close

Using a Spring Boot template and starter

Spring Boot comes with over 40 different starter modules, which provide ready-to-use integration libraries for many different frameworks, such as database connections that are both relational and NoSQL, web services, social network integration, monitoring libraries, logging, template rendering, and the list just keeps going on. While it is not practically feasible to cover every single one of these components, we will go over the important and popular ones to get an idea of the possibilities and the ease of application development that Spring Boot provides us with.

How to do it...

We will start by creating a basic simple project skeleton, and Spring Boot will help us achieve this:

  1. Head over to http://start.spring.io
  2. Fill out a simple form with the details about our project
  3. Click on Generate Project alt + a premade project skeleton will download; this is where we begin

How it works...

You will see the Project Dependencies section, where we can choose the kind of functionalities that our application will perform: Will it connect to a database? Will it have a web interface? Do we plan to integrate with any of the social networks bake in operational support? and so on. By selecting the desired technologies, the appropriate starter libraries will be added automatically to the dependency list of our pregenerated project template.

Before we proceed with the generation of our project, let's go over what exactly a Spring Boot starter is and the benefits it provides us with.

Spring Boot aims to make it easy to get started with creating an application. Spring Boot starters are bootstrap libraries that contain a collection of all the relevant transitive dependencies that are needed to start a particular functionality. Each starter has a special file, which contains the list of all the provided dependencies Spring provides. Let's take a look at the following link for a spring-boot-starter-test definition as an example:

https://github.com/spring-projects/spring-boot/blob/master/spring-boot-project/spring-boot-starters/spring-boot-starter-test/src/main/resources/META-INF/spring.provides

Here we will see the following code:

provides: spring-test, spring-boot, junit, mockito, hamcrest-library, jsonassert, json-path 

This tells us that by including spring-boot-starter-test in our build as a dependency, we will automatically get spring-test, spring-boot, junit, mockito, hamcrest-library,jsonassert, and json-path. These libraries will provide us with all the necessary things in order to start writing application tests for the software that we will develop, without needing to manually add these dependencies to the build file individually.

With more than 100 starters provided, and with the ongoing community additions increasing the list, it is very likely that unless, we find ourselves with the need to integrate with a fairly common or popular framework, there is already a starter out there that we can use.

The following table shows you the most notable ones so as to give you an idea of what is available:

Starter

Description

spring-boot-starter

This is the core Spring Boot starter that provides you with all the foundational functionalities. It is depended upon by all other starters, so no need to declare it explicitly.

spring-boot-starter-actuator

This starter provides you with a functionality to monitor, manage an application, and audit.

spring-boot-starter-jdbc

This starter provides you with a support to connect and use JDBC databases, connection pools, and so on.

spring-boot-starter-data-jpa

spring-boot-starter-data-*

The JPA starter provides you with needed libraries so you can use Java Persistence API (JPA): Hibernate, and others.

Various data-* family starters provide support for a number of datastores, such as MongoDB, Data REST, or Solr.

spring-boot-starter-security

This brings in all the needed dependencies for Spring Security.

spring-boot-starter-social-*

This allows you to integrate with Facebook, Twitter, and LinkedIn.

spring-boot-starter-test

This is a starter that contains the dependencies for spring-test and assorted testing frameworks: JUnit and Mockito, among others.

spring-boot-starter-web

This gives you all the needed dependencies for web application development. It can be enhanced with spring-boot-starter-hateoas, spring-boot-starter-websocket, spring-boot-starter-mobile, or spring-boot-starter-ws, and assorted template-rendering starters: sping-boot-starter-thymeleaf or spring-boot-starter-mustache.

spring-cloud-starter-*

Various cloud-* family starters providing support for a number of frameworks, such as Netflix OSS, Consul, or AWS.

bookmark search playlist font-size

Change the font size

margin-width

Change margin width

day-mode

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Delete Bookmark

Modal Close icon
Are you sure you want to delete it?
Cancel
Yes, Delete