• 框架——容器框架——spring_boot——devtools


      devTools类似于Jrebel,用于实现热部署。开发环境很方便,正式环境,例如生产别使用。

    它的知识点分为三个部分。

    第一部分,搭建环境,即引入devTools的jar包。

    第二部分,devTools的原理。

    第三部分,devTools的配置项。

    1、搭建环境

    1.1  引入Jar

    引入下述的jar包即可。

    <dependency>
    	<groupId>org.springframework.boot</groupId>
    	<artifactId>spring-boot-devtools</artifactId>
    	<scope>runtime</scope>
    	<optional>true</optional>
    </dependency>
    

    1.2  自动注入

    Spring会为devTools自动注入DevToolsPropertyDefaultsPostProcessor。它会加载一些默认的环境变量。

    static {
    	Map<String, Object> properties = new HashMap<>();
    	properties.put("spring.thymeleaf.cache", "false");
    	properties.put("spring.freemarker.cache", "false");
    	properties.put("spring.groovy.template.cache", "false");
    	properties.put("spring.mustache.cache", "false");
    	properties.put("server.servlet.session.persistent", "true");
    	properties.put("spring.h2.console.enabled", "true");
    	properties.put("spring.resources.cache.period", "0");
    	properties.put("spring.resources.chain.cache", "false");
    	properties.put("spring.template.provider.cache", "false");
    	properties.put("spring.mvc.log-resolved-exception", "true");
    	properties.put("server.error.include-stacktrace", "ALWAYS");
    	properties.put("server.servlet.jsp.init-parameters.development", "true");
    	properties.put("spring.reactor.debug", "true");
    	PROPERTIES = Collections.unmodifiableMap(properties);
    }
    

    2、原理

      引用原著中的内容:

      The restart technology provided by Spring Boot works by using two classloaders. Classes that do not change (for example, those from third-party jars) are loaded into a base classloader. Classes that you are actively developing are loaded into a restart classloader. When the application is restarted, the restart classloader is thrown away and a new one is created. This approach means that application restarts are typically much faster than “cold starts”, since the base classloader is already available and populated.

        有两个类加载器,其中base类加载器用于加载不会改变的对象,例如第三方的jar包。Restart类加载器用于加载正在开发的文件,每次项目重启都会重新创建Restart类加载器,但是会复用之前的base类加载器。

    3、配置项

      启用 & 禁用 

    -- 启用或者是禁用,true表示启用,false表示禁用
    spring.devtools.restart.enabled=true
    

      包含 & 排除

    -- 包含&排除,默认情况下,会监听resources,main文件夹下所有文件
    spring.devtools.restart.exclude
    spring.devtools.restart.include
    -- 额外监听的路径
    spring.devtools.restart.additional-paths
    

      触发文件

    -- 默认情况下,监听的文件夹下存在变化时,会触发restart
    -- 指定某个文件后,只有该文件修改才会触发restart
    spring.devtools.restart.trigger-files
    

      查找路径

      全局:会在$HOME/.config/spring-boot目录下查找spring-boot-devtools的properties文件或者是yaml文件。

      单个项目:会在resources/config或者是resources目录下查找spring-boot-devtools的properties文件或者是yaml文件。也可以直接写在application.properties中。

  • 相关阅读:
    2016.11.30
    java韩顺平老师视频有需要可以留言
    UESTC 1425 Another LCIS
    hdu 3308 LCIS
    HDU 3308 LCIS 线段树区间更新
    poj crane
    poj1436 Horizontally Visible Segments
    编程习惯记录
    poj 3225 Help with Intervals
    UVA 1513 Movie collection
  • 原文地址:https://www.cnblogs.com/rain144576/p/16212764.html
Copyright © 2020-2023  润新知