DevTools in Spring Boot 1.3

Spring Boot 1.3 will ship with a brand new module called spring-boot-devtools. The aim of this module is to try and improve the development-time experience when working on Spring Boot applications.

To use the module you simply need to add it as a dependency in your Maven POM:

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

or your Gradle build file:

dependencies {
    compile("org.springframework.boot:spring-boot-devtools")
}

Once included, the spring-boot-devtools module provides a number of nice features that we cover below (If you can’t be bother to read the text, skip to the end of the post for a short video).

Property Defaults

If you’ve used templating technologies such as Thymeleaf with Spring Boot 1.2, you might be familiar with properties such as spring.thymeleaf.cache. These properties are used to disable caching and allow you to update pages without needing to restart your application. Having support for these properties is pretty handy, but remembering to set them during development has always been a bit of a pain.

Now, when you use the spring-boot-devtools module, you no longer need to remember to set the properties. During development caching for Thymeleaf, Freemarker, Groovy Templates, Velocity and Mustache are all automatically disabled.

Automatic Restart

You may have used tools such as JRebel or Spring Loaded in the past to provide instant reload for your Java applications. These tools are great, but they do often require additional configuration or IDE plugins to work (and some of them even cost money!)

With Spring Boot 1.3 we’ve been working on something that’s a little slower than these “instant reload” techniques, and instead works by restarting your application. When you have the spring-boot-devtools module included, any classpath file changes will automatically trigger an application restart. We do some tricks to try and keep restarts fast, so for many microservice style applications this technique might be good enough.

LiveReload

With sensible “cache properties” and “automatic restarts” working, needing to manually click the browser refresh button each time something changes starts to become a little tedious. So to help save your mouse buttons, Spring Boot 1.3 DevTools includes an embedded LiveReload server. LiveReload is a simple protocol that allows your application to automatically trigger a browser refresh whenever things change. Browser extensions are freely available for Chrome, Firefox and Safari from livereload.com.

Remote Debug Tunneling

If you’ve ever tried to host a Java application using Docker, or if you’ve tried a micro PaaS such as Lattice, you may have been frustrated about how difficult it can be to debug your code. You need configure Java to start with -Xdebug and somehow forward the appropriate port so that you can attach the remote debugger.

To help with this, Spring Boot 1.3 can tunnel JDWP (the Java Debug Wire Protocol) over HTTP directly to your application. This can even work with applications deployed to Internet Cloud providers that only expose port 80 and 443 (although since JDWP is quite a chatty protocol this can be quite slow).

Remote Update and Restart

The final trick that DevTools offers is support for remote application updates and restarts. This works by monitoring your local classpath for file changes and pushing them to a remote server which is then restarted. As with local restarts, you can also use this feature in combination with LiveReload.

Video Preview

All the features discussed in this post are already available in Spring Boot 1.3.0.M1 and detailed documentation is available in the reference guide. If you’re not ready to install the bits yourself yet, here’s a short video that shows how they work:

original link:点击这个

时间: 2024-09-30 22:07:52

DevTools in Spring Boot 1.3的相关文章

Spring Boot 属性配置和使用

spring Boot 允许通过外部配置让你在不同的环境使用同一应用程序的代码,简单说就是可以通过配置文件来注入属性或者修改默认的配置. Spring Boot 系列 Spring Boot 入门 Spring Boot 属性配置和使用 Spring Boot 集成MyBatis Spring Boot 静态资源处理 Spring Boot - 配置排序依赖技巧 Spring Boot - DevTools 介绍 Spring Boot 支持多种外部配置方式 这些方式优先级如下: 命令行参数 来

Spring Boot 集成MyBatis

Spring Boot 集成MyBatis 在集成MyBatis前,我们先配置一个druid数据源. Spring Boot 系列 Spring Boot 入门 Spring Boot 属性配置和使用 Spring Boot 集成MyBatis Spring Boot 静态资源处理 Spring Boot - 配置排序依赖技巧 Spring Boot - DevTools 介绍 Spring Boot 集成druid druid有非常多个配置选项,使用Spring Boot 的配置文件能够方便的

2019阿里P7最新总结Spring Boot面试问题

? ? Spring Boot一直是Spring生态系统的关键参与者.该项目通过其自动配置功能使我们的生活更加轻松.在本教程中,我们将介绍在求职面试中可能出现的一些与Spring Boot相关的最常见问题. Spring和Spring Boot有什么区别? Spring Framework提供了多种功能,使Web应用程序的开发更加容易.这些功能包括依赖注入,数据绑定,面向方面的编程,数据访问等等. 多年来,Spring变得越来越复杂,这种应用程序所需的配置量可能会令人生畏.这就是Spring B

使用spring boot devtools不要多此一举加try...catch

spring-boot-devtools是个好东西,在开发调试时可以随时热部署,不用每次手工启停.前两天一个项目查log,发现总有这样的错误日志输出: org.springframework.boot.devtools.restart.SilentExitExceptionHandler$SilentExitException at org.springframework.boot.devtools.restart.SilentExitExceptionHandler.exitCurrentTh

spring boot 1.5.4 集成devTools(五)

上一篇:spring boot 1.5.4 整合JSP(四) 1.1    Spring Boot集成devTools spring boot集成devTools源码:https://git.oschina.net/wyait/springboot1.5.4.git 实现步骤: Eclipse Project 必须开启了Build Automatically,如果关闭了自动编译的功能,热部署无效. 1. pom引入devTools依赖和插件配置 <!-- devtools--> <dep

Spring Boot新模块devtools

Spring Boot 1.3中引入了一个新的模块,devtools. 顾名思义,这个模块是为开发者构建的,目的在于加快开发速度. 这个模块包含在最新释出的1.3.M1中. 自动禁用模板缓存 一般情况下,View层都会应用诸如Thymeleaf之类的模版引擎,这些引擎一般会在启动或者第一次加载时编译自己,所以应用启动以后再修改它们就不会立刻生效. 当然,这种情况下你可以禁用掉缓存已达到快速调试的目的,比如对于Thymeleaf,你需要设置spring.thymeleaf.cache为false.

使用IDEA 中 实现springboot 热部署 (spring boot devtools版)

第一步:添加springboot的配置文件 首先我先贴出我的配置 添加依赖包 <!-- spring boot devtools 依赖包. --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <optional>true</optional> <

spring boot 在IDEA使用devtools热布署不成功,都没有注意的事!

在网上搜索了很多关于spring boot 使用devtools热布署问题的文章,都说不成功的问题主要是下面两点: 1.在settings->build,execution,Deployment->compiler中将Build project automatically选项勾上: 2.按ctrl+shift+alt+/,组合键,选择1.Registry,勾选compiler.automake.allow.when.app.running 最后重起项目,就可以看到热布署的效果了. 但我试了很长

IDEA新建SpringBoot+MySQL+MyBatis+Lombok+Spring Boot DevTools项目

一,IDEA新建SpringBoot+MySQL+MyBatis+Lombok+Spring Boot DevTools项目 1,新建项目的选中项 2,新建后我们需要配置勾选这个自动编译 3,按住shift+alt+ctrl+/,然后选中registry 4,然后选中这个选项 5,然后在 pom.xml文件添加以下代码,开启热部署工具,不配置不生效 <build> <plugins> <plugin> <groupId>org.springframework