spring boot 插件:devtools

spring-boot-devtools

Developer tools are automatically disabled when running a fully packaged application. If your application is launched using java -jar or if it’s started using a special classloader, then it is considered a “production application”. Flagging the dependency as optional in Maven or using compileOnly in Gradle is a best practice that prevents devtools from being transitively applied to other modules using your project

  // maven
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <optional>true</optional>
    </dependency>
</dependencies>

// gradle
dependencies {
    compileOnly("org.springframework.boot:spring-boot-devtools")
}
  • 开发阶段我们会更倾向于实时看到改动产生的效果,因此关闭一些默认的配置是有必要的,比如缓存,我们可以手动application.properties文件配置,比如spring.thymeleaf.cache=false,更直接的,devtools已经为开发环境准备好了配置:
    // DevToolsPropertyDefaultsPostProcessor.class ...
    static {
        HashMap devToolsProperties = new HashMap();
        devToolsProperties.put("spring.thymeleaf.cache", "false");
        devToolsProperties.put("spring.freemarker.cache", "false");
        devToolsProperties.put("spring.groovy.template.cache", "false");
        devToolsProperties.put("spring.mustache.cache", "false");
        devToolsProperties.put("server.session.persistent", "true");
        devToolsProperties.put("spring.h2.console.enabled", "true");
        devToolsProperties.put("spring.resources.cache-period", "0");
        devToolsProperties.put("spring.resources.chain.cache", "false");
        devToolsProperties.put("spring.template.provider.cache", "false");
        devToolsProperties.put("spring.mvc.log-resolved-exception", "true");
        devToolsProperties.put("server.jsp-servlet.init-parameters.development", "true");
        devToolsProperties.put("spring.reactor.stacktrace-mode.enabled", "true");
        PROPERTIES = Collections.unmodifiableMap(devToolsProperties);
    }
  • 对于位于/static, /templates目录下的静态资源,并不需要restart,而是更轻便的live reload,默认情况下/META-INF/ maven, /META-INF/resources, /resources, /static, /public or /templates目录下的改动不会导致restart,当然你可以配置不包含哪些目录或者添加额外的资源目录spring.devtools.restart.exclude=static/,public/ spring.devtools.restart.additional-exclude
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值