Home  >  Article  >  Java  >  What are the advantages of Spring Boot in Java?

What are the advantages of Spring Boot in Java?

不言
不言Original
2018-09-12 14:32:002752browse

This article brings you what are the advantages of Spring Boot in Java? It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

Spring Boot is a new framework provided by the Pivotal team. It is designed to simplify the initial construction and development process of new Spring applications. The framework uses an ad hoc approach to configuration, eliminating the need for developers to define boilerplate configurations. Spring Boot simplifies Spring-based application development, and you can create an independent, production-level Spring application with a small amount of code.

As a Java programmer, if you are tired of the traditional development model and hope to have a brand new framework that can provide rapid development and simple integrated programming experience, it is strongly recommended that you learn about Spring Boot. Spring Cloud may be weakened in the future with the development of Kubernetes and Service Mesh, but the impact of Spring Boot on development is far-reaching.

The birth of Spring Boot

As Spring integrates more and more software, Spring has gradually transformed from a single and concise small framework into a large and comprehensive open source software. The boundaries continued to expand, and later Spring could do almost anything. Mainstream open source software and middleware on the market were supported by Spring corresponding components. After people enjoyed the convenience of Spring, they also encountered some problems.

Every time Spring integrates an open source software, it needs to add some basic configurations. Slowly, as the projects developed by people become larger and larger, it is often necessary to integrate a lot of open source software. Therefore, when using Spring to develop large-scale projects later, it needs to be introduced. There were many configuration files and too many configurations that were difficult to understand and prone to configuration errors. Later, people even called Spring configuration hell.

Spring seems to be aware of these problems, and there is an urgent need for such a set of software to solve these problems. At this time, the concept of microservices is slowly emerging, and the rapid development of small independent applications has become more urgent. Spring has just The advantage lies in such an intersection. The research and development of the Spring Boot project started in early 2013. In April 2014, Spring Boot 1.0.0 was released.

What are the advantages of Spring Boot in Java?

The above picture shows the Baidu Index of Spring Boot from 2014 to 2018. It can be seen that the launch of Spring Boot 2.0 triggered a search peak.

Spring Boot is not intended to replace Spring. Spring Boot is developed based on Spring to make it easier for people to use Spring. Seeing the market response to Spring Boot, Spring officials also attach great importance to the subsequent development of Spring Boot. They have promoted Spring Boot as the company's top project and placed it at the top of the official website. Therefore, the continued development of Spring Boot has also been Be optimistic.

Advantages of using Spring Boot

Spring Boot makes development easier

Spring Boot improves development efficiency in all aspects. We can make a simple comparison:

What do we need to do to develop a web project before using Spring Boot:

  • 1) Configure web.xml, load Spring and Spring mvc

  • 2) Configure database connection and configure Spring transaction

  • 3) Configure reading of loaded configuration files and enable annotations

  • 4) Configure the log file

  • n) After the configuration is completed, deploy tomcat debugging

You may also need to consider the compatibility of various versions and the feasibility of jar package conflicts.

So what operations do we need to develop a web project after using Spring Boot?

  • 1) Log in to the URL http://start.spring.io/ and select the corresponding component to download directly

  • 2) Import the project directly Development

There is a huge contrast between the N steps above and the 2 steps below. This is just in the aspect of setting up the development environment.

Spring Boot makes testing easier

Spring Boot’s support for testing is not unpowerful. Spring Boot has built-in 7 powerful test frameworks:

  • JUnit: A Java language unit testing framework

  • Spring Test & Spring Boot Test: Provides integration testing and tool support for Spring Boot applications

  • AssertJ: A Java testing framework that supports streaming assertions

  • Hamcrest: A matcher library

  • Mockito: A java mock framework

  • JSONassert: an assertion library for JSON

  • JsonPath: JSON XPath library

us You only need to introduce the spring-boot-start-test dependency package into the project to test various situations such as database, Mock, and Web.

Spring Boot makes configuration easier

Spring Boot makes configuration simpler. Speaking of which, we need to understand the core idea of ​​Spring Boot: convention is better than configuration. So what is convention over configuration? Convention over configuration, also known as programming by convention, is a software design paradigm that aims to reduce the number of decisions software developers need to make and gain the benefits of simplicity without sacrificing flexibility.

The essence is that developers only need to specify the parts of the application that do not conform to the contract. For example, if there is a class named User in the model, the corresponding table in the database will be named user by default. Only when deviating from this convention, such as naming the table "user_info", do you need to write configuration about this name.

The Spring Boot system fully demonstrates the idea of ​​​​convention over configuration. Everything from configuration files and default configurations of middleware to built-in containers and various Starters in the ecosystem all follow this design rule. Spring Boot encourages each software organization to create its own Starters. One of the core components of creating a Starter is the autoconfigure module. The core function of the Starter is to automatically assemble and configure properties by default at startup.

Spring Boot makes deployment easier

Speaking of Spring Boot making deployment easier, we have to talk about Spring Boot embedded containers. Embedded containers not only make deployment easier, but also bring great convenience during the development and debugging phase. Compared with the tediousness of configuring Tomcat when developing Web projects in the past, everyone will have a deeper understanding when developing using Spring Boot embedded containers. Feeling. Using Spring Boot to develop web projects allows us to focus on writing business code without having to worry about the environment of the container.

But embedded containers actually bring more changes to deployment. Now Maven and Gradle have become indispensable building tools for our daily development. Using these tools, it is easy to package projects into Jar or War. package, we only need one command to start the project on the server. Spring Boot supports adding customization at startup, such as setting the application's heap memory, garbage collection mechanism, log path, etc.

The development of virtualization technology has brought us more possibilities. We can use containerization technology to mirror the Spring Boot project and achieve elastic expansion, dynamic deployment, etc. according to the container cluster strategy. . Therefore, Spring Boot Docker Jenkins will make the deployment of Spring Boot projects simpler and smarter.

Spring Boot makes monitoring easier

It can be said that Spring Boot is an open source software that comes with its own monitoring. At the beginning of the design, application monitoring issues were taken into consideration and a special A monitoring component is used to complete this work. This component is
Spring Boot Actuator. Spring Boot Actuator is an integrated function for application system monitoring provided by Spring Boot. It can view detailed information of application configuration, such as automated configuration information, created Spring beans, and some environment properties.

Of course, although Spring Boot Actuator can monitor the health of a Spring Boot application, in fact, current systems require many services to cooperate with each other to complete the work. How to monitor all Spring Boot projects through a monitoring software? will become more urgent. Some people in the open source community are also aware of this problem and have made a powerful monitoring software based on Spring boot actuator. This software is Spring Boot admin.

Using Spring Boot Admin can not only monitor Spring Boot projects, but also Spring Cloud projects. Therefore, after using the Spring Boot project, we monitor the Spring Boot cluster effect as follows:

What are the advantages of Spring Boot in Java?

Simple, intuitive and easy to use are its characteristics. It can also provide alarm services for some special situations. Therefore, using Spring Boot Actuator solves the monitoring problem of a single Spring Boot, and using Spring Boot Admin solves the problem of monitoring the entire cluster.

Related recommendations:

Detailed explanation of Spring Boot in java

java spring boot 1.5.4 log management

The above is the detailed content of What are the advantages of Spring Boot in Java?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn