devtools模塊,是爲開發者服務的一個模塊。主要的功能就是代碼修改後通常在5秒以內就會自動從新加載至服務器,至關於restart成功。java
在發現代碼有更改以後,自動從新啓動應用,可是其速度比手動中止後再啓動還要快些,更快這裏指的不是節省出來的手工操做的時間。git
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.jege.spring.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>spring-boot-mybatis</name>
<url>http://maven.apache.org</url>
<!-- 公共spring-boot配置,下面依賴jar文件不用在寫版本號 -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.1.RELEASE</version>
<relativePath />
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<!-- web -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- 熱部署 -->
<!-- devtools能夠實現頁面熱部署(即頁面修改後會當即生效,這個能夠直接在application.properties文件中配置spring.thymeleaf.cache=false來實現) -->
<!-- 實現類文件熱部署(類文件修改後不會當即生效),實現對屬性文件的熱部署。 -->
<!-- 即devtools會監聽classpath下的文件變更,而且會當即重啓應用(發生在保存時機),注意:由於其採用的虛擬機機制,該項重啓是很快的 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<!-- optional=true,依賴不會傳遞,該項目依賴devtools;以後依賴boot項目的項目若是想要使用devtools,須要從新引入 -->
<optional>true</optional>
</dependency>
</dependencies>
<build>
<finalName>spring-boot-devtools</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<!-- 若是沒有該項配置,實際測試ok -->
<!-- <fork>true</fork> -->
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
package com.jege.spring.boot;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/** * @author JE哥 * @email 1272434821@qq.com * @description:spring boot 啓動類 */
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
#添加那個目錄的文件須要restart
spring.devtools.restart.additional-paths=src/main/java
#排除那個目錄的文件不須要restart
spring.devtools.restart.exclude=static/**,public/**
package com.jege.spring.boot.devtools;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/** * @author JE哥 * @email 1272434821@qq.com * @description:看看devtools模塊的快速 */
@RestController
public class HelloController {
@RequestMapping("/hello")
public String hello() {
// System.out.println("test");
return "Hello World";
}
}
https://github.com/je-ge/spring-bootgithub
若是以爲個人文章對您有幫助,請予以打賞。您的支持將鼓勵我繼續創做!謝謝!
web