博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
DevTools in Spring Boot 1.3
阅读量:7042 次
发布时间:2019-06-28

本文共 3735 字,大约阅读时间需要 12 分钟。

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:

org.springframework.boot
spring-boot-devtools

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  or  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 .

Remote Debug Tunneling

If you’ve ever tried to host a Java application using , or if you’ve tried a micro PaaS such as , 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  and detailed documentation is available in the . If you’re not ready to install the bits yourself yet, here’s a short video that shows how they work:

original link:

转载地址:http://ymqal.baihongyu.com/

你可能感兴趣的文章
PHP7 的抽象语法树(AST)带来的变化
查看>>
如何在Mac 终端升级ruby版本
查看>>
国际编程教育权威科学家菲利普.米勒教授来访 SegmentFault 总部
查看>>
API 标准化成为技术团队面临的最大挑战
查看>>
CSS 小三角
查看>>
Ruby on Rails 曝路径穿越与任意文件读取漏洞
查看>>
分享一个基于 Node.js 的 Web 开发框架 - Nokitjs
查看>>
mysql 简单全量备份和快速恢复
查看>>
全面解密QQ红包技术方案:架构、技术实现、移动端优化、创新玩法等 ...
查看>>
Python进阶:设计模式之迭代器模式
查看>>
Java是如何实现平台无关性的
查看>>
线上马戏团对接协议部分介绍
查看>>
一文纵览自然语言生成的发展
查看>>
常见seo骗局
查看>>
RNA药物研发初创公司Panorama Medicine完成370万美元种子轮融资 ...
查看>>
我国抢占“第二次量子革命”全球制高点
查看>>
Living the Stream: Live-streaming in China
查看>>
CommonJS/AMD/CMD/UMD概念初探
查看>>
字符串拷贝记得strcpy
查看>>
[微信小程序]通过计算其他view的高度,动态给定scroll-view的高度
查看>>