快捷搜索:  汽车  科技

springboot项目部署和访问:SpringBoot开启热部署模式

springboot项目部署和访问:SpringBoot开启热部署模式<groupId>org.springframework.boot</groupId>       <dependency> 2、使用 Spring Loaded二、Eclipse或Spring Tool Suite的实现方式 1、pom.xml文件增加

前言:

在做Spring Boot 项目调试时总是会来回修改代码,重启项目,为了方便项目修改后,立即能看到效果。

springboot项目部署和访问:SpringBoot开启热部署模式(1)

一、实现的方式概述

1、使用 spring-boot-devtools

2、使用 Spring Loaded

二、Eclipse或Spring Tool Suite的实现方式

1、pom.xml文件增加

       <dependency>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-devtools</artifactId>

<optional>true</optional>

</dependency>  

2、工程配置

Project -> build Automatically 选中

三、IEDA的实现方式

1、pom.xml文件增加 spring-boot-devtools

    <dependency>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-devtools</artifactId>

<optional>true</optional>

   </dependency>

2、pom.xml增加 springloaded

<build>

<plugins>

<plugin>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-maven-plugin</artifactId>

<dependencies>

<dependency>

<groupId>org.springframework</groupId>

<artifactId>springloaded</artifactId>

<version>1.2.5.RELEASE</version>

</dependency>

</dependencies>

</plugin>

</plugins>

</build>

3、修改配置

打开IDEA ,File->Settings-> Build-Execution-Deployment -> Compiler,勾选 Build Project Automatically.

springboot项目部署和访问:SpringBoot开启热部署模式(2)

4、按 Shift Ctrl A (windows mac是 command shift A)

将看到弹窗 Enter Action or option name,输入"Registry",双击第一项"Registry..." ,会弹出另一个窗口,寻找 < compiler.automake.allow.when.app.running> 选中,参考如图:

springboot项目部署和访问:SpringBoot开启热部署模式(3)

5、重启IDE (与Eclipse不一样,IDEA需要重启下)

四、测试方法

一、Eclipse测试

1、运行项目

2、修改类-->保存:应用会重启

3、修改配置文件-->保存:应用会重启

4、修改页面-->保存:应用会重启,页面会刷新(原理是将spring.thymeleaf.cache设为false)

二、 IDEA测试

1、运行项目

2、修改controller中代码,会发现显示结果跟着变化。

3、修改html页面 后再刷新页面,会发现显示结果跟着变化。

五、热部署的注意事项

1、如果使用模板引擎,关闭缓存

在application.properties中添加

#禁止thymeleaf缓存(建议:开发环境设置为false,生成环境设置为true)

spring.thymeleaf.cache=false

2、开启热部署后,session每次都会重置的

猜您喜欢: