- Mastering Spring Boot 2.0
- Dinesh Rajput
- 550字
- 2021-06-25 21:29:10
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.
- Excel 2013使用詳解
- Excel完全自學教程
- 財務必須知道的115個Excel函數
- Excel 職場手冊:260招菜鳥變達人
- 中文版AutoCAD 2016園林設計從入門到精通
- Office 2003辦公應用實戰從入門到精通
- 巧學巧用Excel函數:掌握核心技能,秒變數據分析高手
- PowerPoint 2013從入門到精通
- 大話PPT:幻燈片制作真經
- Office 2007中文版實用教程
- Intuit QuickBooks Enterprise Edition 12.0 Cookbook for Experts
- Office 2003辦公應用從入門到精通
- Office 2013從新手到高手
- 精英演示:PPT的商務演示藝術
- PowerPivot for Advanced Reporting and Dashboards