我们知道,spring-boot-devtools是spring提供的快速的启动Spring Boot应用,可以为我们节省大量的时间。 1-基本

  • 基本 1.首先是在pom.xml文件中添加如下依赖和插件:
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <fork>true</fork>
            </configuration>
        </plugin>
    </plugins>
</build>
复制代码

2.在application.properties中添加

spring.devtools.restart.enabled: true
#设置重启的目录
#spring.devtools.restart.additional-paths: src/main/java
#classpath目录下的WEB-INF文件夹内容修改不重启
spring.devtools.restart.exclude: WEB-INF/**
复制代码

3.如果是IDEA还需要再配置一下,具体如下: 1)File->Settings->Buide、execution->Compiler,选中Build Project automatically,这样当我们修改了Java类后,IDEA就会自动编译了。

2)使用快捷键Ctrl+Shift+Alt+/,选择弹框中的Registry,勾上 Compiler autoMake allow when app running
此时修改java类就不用自己动手再次编译了,应用会重启,相应的页面也会刷新