SpringBoot summary (7) - core functions of spring-boot-devtools

Original link

 

Of course, 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 reaction of Spring Boot, Spring officials also attach great importance to the follow-up development of Spring Boot. Spring Boot has been promoted as the company's top-level project and placed first on the official website. Therefore, the continuous development of Spring Boot has also been Optimistic.

Spring Boot features

Use the Spring project boot page to build a project in a few seconds. It is
convenient to export various forms of services, such as REST API, WebSocket, Web, Streaming, and Tasks.
Very simple security strategy integration.
Support for relational and non-relational databases.
Support for embedding during runtime Containers, such as Tomcat, Jetty,
powerful development kits, support hot start,
automatic management of dependencies,
built-in application monitoring,
support various IEDs, such as IntelliJ IDEA, NetBeans
Spring Boot. These features will bring us great advantages in research and development, we can separate them below To introduce.

Advantages of
using Spring Boot Using Spring Boot to develop projects will bring us a very wonderful development experience, which can be explained from the following aspects:

Spring Boot makes development easier.
Building a development environment
Spring Boot improves development efficiency in an all-round way. We can simply make a comparison:

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

1) Configure web.xml, load Spring MVC and Spring
2) configure a database connection configuration Spring transaction
3) configuration read load profiles, open notes
4) configuration log file
...
after n) configuration to deploy Tomcat debugging
You may also Need to consider the compatibility of each version, the various 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 components to download directly.
2) Import the project and develop directly
. The N steps above and the 2 steps below form a huge contrast;

Spring DevTools

Spring Boot also provides a special component package: Spring DevTools, DevTools includes a set of additional tools that can make the application development experience more enjoyable. spring-boot-devtools provides some development features for applications, including default value settings, automatic restart, livereload, etc.

1. The default value of the attribute

Some libraries supported by Spring Boot will use caching to improve performance. For example, the template engine will cache compiled templates to avoid repeated parsing of template files. In addition, Spring mvc can add HTTP cache headers to the response when serving static resources.

Although caching is very beneficial in production, it can be counterproductive during development. It prevents you from seeing the changes you just made in the application. Therefore, spring-boot-devtools will disable these caching options by default.

2. Automatic restart

In the Spring Boot project that uses the spring-boot-devtools dependency package, we only need a simple configuration to make the project have the function of automatic restart, so that we can debug the code in the development process more efficiently and naturally.

The principle of automatic restart is that Spring Boot uses two classloaders: classes that do not change (such as third-party jars) are loaded by the base class loader, and classes under development are loaded by the restart class loader. When the application restarts, the restart class loader is thrown away and rebuilt, while the base class loader remains unchanged. This method means that the application restart is usually much faster than a "cold start" because the base class loader is already available and filled . Therefore, when we start devtools, file changes in the classpath will cause the application to restart automatically.

》Simple text is not easy to understand, let’s demonstrate:

1. Log in to the URL
https://start.spring.io/
2. Fill in the web and devtools components and press
Enter to generate a springboot project

23

Guess you like

Origin blog.csdn.net/lsx2017/article/details/114005518