Spring Boot学习笔记-1

Spring Boot 学习笔记

本篇文章有以下知识点

  • Developer tools

Developer tools

应用程序如果使用了spring-boot-devtools,当classpath下面的文件发生改变时就会重启。

Maven 添加


    
        org.springframework.boot
        spring-boot-devtools
        true
    

自动重启(Automatic restart)

Restart vs Reload

The restart technology provided by Spring Boot works by using two classloaders. Classes that don’t change (for example, those from third-party jars) are loaded into a base classloader. Classes that you’re 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.

意思是说Spring Boot 用了2个类加载器来加载程序中的class文件,那些固定不变的类(第三方类)用一个类加载器,程序本身的类用另一个类加载器(restart classloader)。当Spring Boot检测到改变时就用restart类加载器来启动,相比冷启动来说速度要快很多。

排除加载一些文件(Excluding resources)

像一些资源文件,比如,/META-INF/maven, /META-INF/resources ,/resources ,/static ,/public or /templates就不需要出发程序重启,所以需要排除。在application.properties文件中添加

spring.devtools.restart.exclude=static/**,public/**

在生产环境中这些文件默认会缓存起来,但是在开发环境中不需要缓存,在application.properties文件中添加

    spring.thymeleaf.cache=false

spring-boot-devtools 默认为false


你可能感兴趣的