Spring-boot-devtools is a module for developers, and the most important feature is the automatic application of code changes to the latest apps. Related blog: Click to open the link
The principle is to restart the application after discovering that the code has changed, but faster than the speed of the manual stop, and faster than the time saved by manual operation.
The underlying principle is to use two ClassLoader, one ClassLoader to load the classes that will not change (third-party jar packages), and another ClassLoader to load the changed classes, called Restart ClassLoader
, so that when there is code change, the original restart ClassLoader is discarded, re-create a restart ClassLoader, due to the need to load fewer classes, so a faster restart time (less than 5 seconds).
Since Devtools is only in Spring milestone repository. Warehouse is available, and the default warehouse version is 1.2.5.RELEASE, so you need to configure the warehouse address in the Pom.xml file.
[HTML]View PlainCopy
- <repositories>
- <repository>
- <ID>spring-milestones</ID>
- <name>spring milestones</name>
- <URL>http://repo.spring.io/milestone</url>
- <snapshots>
- <enabled>false</enabled>
- </Snapshots>
- </repository>
- </repositories>
Then change the parent label
[HTML]View PlainCopy
- <parent>
- <groupId>org.springframework.boot</groupId>
- <artifactid>spring-boot-starter-parent</artifactid>
- <version>1.3.0.m2</version>
- </Parent>
Finally add the module dependency can be
[HTML]View PlainCopy
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactid>spring-boot-devtools</artifactid>
- </Dependency>
As for the use of the module, as long as the dependency is written in the line, do not need other special action, use the example click here to have a video show, or pretty clear.
Pay special attention to Because the inheritance of the Pom.xml version is 1.3.0.m2, the original dependent on the inside if you omit version, but in the 1.3.0.m2 without the module will be error, this time only need to manually add the dependent version coordinates, written as the original 1.2.5.RELEASE can be.
Note the point:
1.spring-boot-tools and Spring-boot versions to be consistent
MAVEN Engineering uses Spring-boot-devtools for hot deployment, changing code to avoid restarting the Web container