Spring-boot-devtools (Hot deployment of Springboot)

Source: Internet
Author: User

What is hot deployment?

We all know that in the project development process, often change the page data or modify data structure, in order to show the effect of changes, often need to restart the application to see the effect of change, in fact, is to recompile the creation of a new Class file, the file is recorded with the code and other corresponding information, and then Class The file will be loaded by the ClassLoader of the virtual machine.

And the heat deployment is the use of this feature, it is heard if a Class file changes, it will create a new claassloader to load the file, after a series of processes, the results will be presented to our eyes.

Class loading mechanism

Classes in Java can be compiled into a class file that stores bytecode, which stores a variety of information and is eventually loaded into a virtual machine to be used for running.

Class loading mechanism (excerpt from "in-depth understanding of Java virtual machines")

The virtual machine loads the data of the description class from the class file into memory, verifies the data, parses and initializes it, and eventually forms a Java type that can be used directly by the virtual machine.

Spring Boot for hot deployment

The Spring Boot implementation is simple, and we use the project created in the previous chapter Springboot to create a simple web interaction app to demonstrate.

    • Using Spring Loaded
    • Using Spring-boot-devtools

The first way is slightly

Highlights the hot deployment of Spring boot in idea:

1. Import the dependent package (preferably core-devtools on the project under construction)

<dependency>     <groupId>org.springframework.boot</groupId>     <artifactId> spring-boot-devtools</artifactid>     <scope>runtime</scope>  <!--  
The <optional>true</optional> dependency package does not pass, and if the package is in the parent Pom, if the other subproject needs to use a hot deployment dependency package, you must also import
- <optional>true</optional></dependency>

2. Join the Compile node (Spring-boot-maven-plugin is already in Springboot , so add the contents of the configuration tag directly)

<build>        <plugins>            <plugin>                <groupid>org.springframework.boot</groupid >                <artifactId>spring-boot-maven-plugin</artifactId>                <configuration>
<!--Without this configuration, this devtools will not work, i.e. the app will not restart--> <fork>true</fork> </configuration> </plugin> </plugins> </build>

3. Modify the configuration to achieve idea automatic compilation

3.1 Settings-complier-build Project automatically--tick

3.2. CTRL + SHIFT + A--In the dialog box that appears, type: Registry---Find and tick compiler.automake.allow.when.app.running

4. Writing test methods

4.1 Modifying the return value

4.2 Add method to test whether the new method can be accessed correctly

4.3 Add a new test class to test if you can access it correctly

5. Description:

  <optional>true</optional>   Indicates whether the dependency is passed (true means that it can be passed)

If the dependency is in the parent Pom, and the <optional>true</optional> setting is in place, its child module implements automatic deployment. ----This is not related to this configuration, to false or automatic deployment, because this is the cause of the parent-child program.

Spring-boot-devtools (Hot deployment of Springboot)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.