原文:https://www.cnblogs.com/TechSnail/p/7690829.html    &&   https://blog.csdn.net/qq_31293575/article/details/80654132

扩展:

  https://blog.csdn.net/diaomeng11/article/details/73826564

  https://blog.csdn.net/z15732621582/article/details/79439359  : bean.xml配置的项目

  https://blog.csdn.net/u011499747/article/details/71746325  : <excludeDevtools>false</excludeDevtools>为了安全 远程应用排除 devtools

===前言===start==========================================================

spring boot 热部署devtools实现

 

1.devtools

  spring为开发者提供了一个名为spring-boot-devtools的模块来使Spring Boot应用支持热部署,提高开发者的开发效率,无需手动重启Spring Boot应用。

2.项目搭建

  本文是采用IDEA搭建的Spring Boot应用,通过spring-boot-devtools配置,可以支持修改java文件会自动重启程序,一些资源无需触发重启,例如thymeleaf模板文件就可以实时编辑。默认情况下,更改/META-INF/maven,/META-INF/resources ,/resources ,/static ,/public 或/templates下的资源不会触发重启,而是触发livereload。devtools模块包含一个嵌入的livereload服务器,可以在资源变化时用来触发浏览器刷新。浏览器需要在livereload.com下载安装扩展。 例如Chrome浏览器在应用商店安装livereload插件后,在要自动刷新的页面点击对应的图标,启动应用后更新页面内容或者css等都会触发页面自动刷新。

3.livereload

  livereload 通过引入的脚本livereload.js在 livereload 服务和浏览器之间建立了一个 WebSocket 连接。每当监测到文件的变动,livereload 服务就会向浏览器发送一个信号,浏览器收到信号后就刷新页面,实现了实时刷新的效果。每次启动时,需要点击对应的图标,如下图所示。

4.项目代码配置

(1)pom.xml配置文件

1
2
3
4
5
6
7
8
9
10
11
12
<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-devtools</artifactId>
   <optional>true</optional>
</dependency>
<plugin>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-maven-plugin</artifactId>
   <configuration>
      <fork>true</fork<!-- 如果没有该配置,devtools不会生效 -->
   </configuration>
</plugin>

(2)yml配置

1
2
3
4
5
6
devtools:
  livereload:
    enabled: true #是否支持livereload
    port: 35729
  restart:
    enabled: true #是否支持热部署

1.引入依赖

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<!-- optional=true, 依赖不会传递, 该项目依赖devtools;
之后依赖boot项目的项目如果想要使用devtools, 需要重新引入 -->
<optional>true</optional>
</dependency>

===前言===end==========================================================

2.配置文件

#开启或者关闭freemarker和thymeleaf的页面缓存
spring.freemarker.cache=false
spring.thymeleaf.cache=true
spring.devtools.restart.enabled=true
#需要开启热部署的文件目录
spring.devtools.restart.additional-paths=src/main/java
#使用了mybatis好像需要设置,应该没有必要。且生产环境需要移除
#restart.include.mapper=/mapper-[\\w-\\.]+jar
#restart.include.pagehelper=/pagehelper-[\\w-\\.]+jar
#静态文件下不需要重启
#spring.devtools.restart.exclude=static/**,public/**
#spring.devtools.restart.exclude=WEB-INF/**
3.更改idea配置
  1) “File” -> “Settings” -> “Build,Execution,Deplyment” -> “Compiler”,选中打勾 “Build project automatically” 。

  2) 组合键:“Shift+Ctrl+Alt+/” ,选择 “Registry” ,选中打勾 “compiler.automake.allow.when.app.running”

4.Chrome禁用缓存(如果还是无法使用)

  F12或者“Ctrl+Shift+I”,打开开发者工具,“Network” 选项卡下 选中打勾 “Disable Cache(while DevTools is open)”

IDEA 热部署- 自动编译设置的更多相关文章

  1. IDEA+Tomcat热部署自动编译

    https://www.cnblogs.com/1024zy/p/6344000.html 之前太傻瓜了,一直以为用了IDEA改了类或者js的时候全都要手动构建发布,其实不用,IDEA这么好的工具怎么 ...

  2. idea热部署+自动编译

    https://blog.csdn.net/z15732621582/article/details/79439359

  3. Thymeleaf学习记录(2)--自动编译设置

    了方便每次修改HTML文件都能实时刷新,做一下更改. 在application.properties文件加入以下命令: #thymeleaf start spring.thymeleaf.mode=H ...

  4. IDEA热部署自动重启服务问题

    新接手项目过于庞大,从eclipse果断换成了IDEA.因为IDEA有免费的热部署,咳咳咳... 但是,手贱的我在下面这张状态下,直接OK了,TM,这不是我要的热部署啊,这是重新启动啊,但是勾选了do ...

  5. IDEA自动编译设置

    ctrl+alt+s: ctrl+shift+alt+/:

  6. 在IDEA上对SpringBoot项目配置Devtools实现热部署

    spring为开发者提供了一个名为spring-boot-devtools的模块来使Spring Boot应用支持热部署,提高开发者的开发效率,无需手动重启Spring Boot应用. devtool ...

  7. SpringBoot添加热部署

    一.导入依赖 <!--热部署--> <dependency> <groupId>org.springframework.boot</groupId> & ...

  8. Jrebel实现tomcat热部署,遇到的问题以及解决办法,详解

    我的安装的详细过程: 下载Jrebel:  https://github.com/ilanyu/ReverseProxy/releases/tag/v1.4 我的是winx64,所以选择如下的: 下载 ...

  9. maven 使用之自动编译热部署设置

    参见创建webapp项目 eclipse Maven 使用记录 ------ 建立 webapp项目 在maven中为实现热部署设置,部署至webapp,即webroot 设置classes输出目的地 ...

随机推荐

  1. day19 反射

    今日所学 : 1. isinstance , type , issubclass 2.如何区分方法和函数(代码) 3.反射(重要) 1. isinstance ,type ,issubclass is ...

  2. js 动态绑定鼠标事件

    <script> function getElementsByClassName(n) { var classElements = [],allElements = document.ge ...

  3. dubbo-admin 无法支持JDK1.8

    dubbo-admin 无法支持JDK1.8怎么处理? 1.从git上下载最新源码 https://github.com/alibaba/dubbo 2.编译war包,或直接容器启动

  4. 秦皇岛CCPC的失败总结

    个人状态原因:尤其是我,在比赛前没有很好的做准备,还一直看小说,前两天我们本来应该好好打两场训练赛的时候却没有打,然后一直在玩手机,比赛前一天,我下午就不小心睡着了,然后晚上醒来睡不着第二天的精神状态 ...

  5. netty---------write flush两个方法到底做了什么?

    上一篇已经看到:unsafe的read方法,把channel中的数据read到byteBuff中的byteBuffer里.那么根据猜想,下面要进行的应该是nio 的 channel的write(byt ...

  6. 设置table中的td一连串内容自动换行

    遇到一长串字母撑出了td宽度,导致整个表格错乱,如图: , 解决办法: 第一: table 加上css: table-layout: fixed;(此css属性 表示 列宽由表格宽度和列宽度设定.不会 ...

  7. Python 基础day4

    整体大纲关于占位符 tpl = "i am %s" % "alex"   tpl = "i am %s age %d" % ("a ...

  8. Python 爬虫的工具列表大全

    Python 爬虫的工具列表大全 这个列表包含与网页抓取和数据处理的Python库.网络 通用 urllib -网络库(stdlib). requests -网络库. grab – 网络库(基于pyc ...

  9. 2017ICPC南宁赛区网络赛 Train Seats Reservation (简单思维)

    You are given a list of train stations, say from the station 111 to the station 100100100. The passe ...

  10. HDU 6124 17多校7 Euler theorem(简单思维题)

    Problem Description HazelFan is given two positive integers a,b, and he wants to calculate amodb. Bu ...