Springboot热部署相关配置

Springboot热部署配置(Thyemleaf、Idea、Devtools)

LengToo灯泡爱.png

在开发中反复修改类、页面等资源,每次修改后都是需要重新启动才生效,浪费了大量的时间,Spring提供了一个名为spring-boot-devtools的模块来使Spring Boot应用支持热部署,提高开发者的开发效率,无需手动重启Spring Boot应用。

一、devtools原理及引入

  • 原理:
    使用了两个ClassLoader,一个Classloader加载那些不会改变的类(第三方Jar包),另一个ClassLoader加载会更改的类,称为 restart ClassLoader,这样在有代码更改的时候,原来的restart ClassLoader 被丢弃,重新创建一个restart ClassLoader,由于需要加载的类相比较少,所以实现了较快的重启时间。

  • pom依赖:

    
    
        org.springframework.boot
        spring-boot-devtools
        true 
    
    
    
        
            
                org.springframework.boot
                spring-boot-maven-plugin
                
                    true 
                
            
        
    
    

二、application.yml配置

  1. Thyemleaf模板缓存禁用:
    # 模板引擎
    thymeleaf:
        mode: HTML
        encoding: utf-8
        # 禁用缓存
        cache: false
    
  2. 热部署开启及自定义
     # 服务模块
      devtools:
        restart:
          # 热部署开关
          enabled: true
          #禁用日志报告
    #      log-condition-evaluation-delta: false
          #不需要修改触发重启的文件目录
    #      exclude: static/,public/
          #默认配置下还需要在新增的排除目录
    #      additional-exclude:
          #添加需要监视需改文件后重启的路径
    #      additional-paths:
    

三、Idea设置

  1. File --> Settings --> Build,Execution,Deployment --> Compiler,勾选
Springboot热部署相关配置_第1张图片
Idea配置1.png
  1. 使用快捷键Crtl+Shift+Alt+/,并打开Registry,勾选图中红框所示
Springboot热部署相关配置_第2张图片
Idea配置2.png
Springboot热部署相关配置_第3张图片
Idea配置3.png
  1. 重启项目。至此,修改页面(Idea自动保存)刷新后,即可看到修改的内容。

你可能感兴趣的:(Springboot热部署相关配置)