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