Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Mastering Spring Boot 2.0

You're reading from   Mastering Spring Boot 2.0 Build modern, cloud-native, and distributed systems using Spring Boot

Arrow left icon
Product type Paperback
Published in May 2018
Publisher Packt
ISBN-13 9781787127562
Length 390 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Dinesh Rajput Dinesh Rajput
Author Profile Icon Dinesh Rajput
Dinesh Rajput
Arrow right icon
View More author details
Toc

Table of Contents (17) Chapters Close

Preface 1. Getting Started with Spring Boot 2.0 2. Customizing Auto-Configuration in Spring Boot Application FREE CHAPTER 3. Getting Started with Spring CLI and Actuator 4. Getting Started with Spring Cloud and Configuration 5. Spring Cloud Netflix and Service Discovery 6. Building Spring Boot RESTful Microservice 7. Creating API Gateway with Netflix Zuul Proxy 8. Simplify HTTP API with Feign Client 9. Building Event-Driven and Asynchronous Reactive Systems 10. Building Resilient Systems Using Hystrix and Turbine 11. Testing Spring Boot Application 12. Containerizing Microservice 13. API Management 14. Deploying in Cloud (AWS) 15. Production Ready Service Monitoring and Best Practices 16. Other Books You May Enjoy

Simplifying Spring application development using Spring Boot

As we have discussed in the previous section, the Spring Framework provides lot of flexibility to configure beans in the Spring application in multiple ways such as XML, annotation, and Java configuration. But remember, if the number of modules and features increases in the Spring application, it also increases the complexity in the configuration. After a point, your Spring application tends to become tedious and error-prone.

Here, Spring Boot comes into the picture to address the complexity of the configuration of your Spring application.

Spring Boot does exactly what you are looking for. It will do things automatically for you but allows you to override the defaults if required. (Remember the point about it being an opinionated framework?)

Spring Boot is not a separate framework, but it is Spring at heart. It is built on top of the Spring Framework to remove tedious work from the developer end and allow developers to focus on the business code with minimal or zero configurations.

See the following diagram that shows what Spring Boot is exactly:


In the preceding diagram, you can see that Spring Boot is the surface layer over the Spring Framework, with all of the modules such as Web (MVC), JDBC, Security, Batch, and so on. It presents a small surface area for User to approach and extract value from the rest of Spring.

Suppose you are working with a task, a Hello World web application. If you are choosing to develop with the Spring Framework, what would you need to do?

The following are the bare minimum configurations required for a small web application:

  • Creating a project structure either by using Maven or Gradle and defining required dependencies such as Spring MVC and the Servlet API dependencies for your case.
  • A deployment descriptor file, that is, web.xml. In the case of Java configuration, you require the WebApplicationInitializer implementation class that declares Spring's DispatcherServlet.
  • The Spring MVC configuration class to enable the Spring MVC module for your Hello World application.
  • You have to create a controller class that will respond to your request.
  • You require a web application server such as Tomcat.

Of these points, most are generic boilerplate code and common configuration for a Spring web application, except writing application-specific controllers. So, Spring Boot provides all common configurations and boilerplate code based on the available library of the classpath. You don't need to take responsibility for writing this common and generic code.

Let's create the same Hello World application using Spring Boot. Suppose for a moment we are using a Groovy-based controller class as follows:

@RestController
class HelloController {
   @GetMapping("/")
   String hello() {
         "Hello World!!!"
   }
} 

This code is a complete Spring web application, with nothing required to configure. No web.xml file, no build specification, and not even an application server. This is the entire application. We can run this application using Spring Boot CLI with the following command:

$ Spring run HelloController.groovy

So, you can see how Spring Boot simplifies Spring application development. We will also see the same application using Java in the next section of this chapter.

Spring Boot does not compete with the Spring or Spring MVC Framework. It makes it easy to use them in the Spring application.
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime