Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Boot Devtools by Example

According to the Spring Boot Devtools docs, devtools won't run in "production mode"; that is, if you execute your Spring Boot app with java -jar .., then it won't use devtools' built-in JVM magic. However, the Spring Boot starter docs only show you one way of running your Spring Boot application...via java -jar....

So first I'm wondering: How do I run my Spring Boot app in non-production mode? I know you can run your app with Spring Boot CLI (e.g. spring run), but is that the only way?

Also, the same devtools docs mention you can explicitly remove the devtools jar from your production binary by using some excludeDevtools option, but they never explain where/how to use this. Any examples/ideas here?

like image 845
smeeb Avatar asked May 23 '16 17:05

smeeb


People also ask

How do I use Devtools in spring boot?

Spring Boot includes an additional set of tools that can make the application development experience a little more pleasant. The spring-boot-devtools module can be included in any project to provide additional development-time features. To include devtools support, simply add the module dependency to your build: Maven.

What is Devtool dependency in spring boot?

DevTools stands for Developer Tool. The aim of the module is to try and improve the development time while working with the Spring Boot application. Spring Boot DevTools pick up the changes and restart the application. We can implement the DevTools in our project by adding the following dependency in the pom. xml file.

How do I remove spring boot Devtools dependency on production deployments?

If you want to ensure that devtools is never included in a production build, you can use the excludeDevtools build property to completely remove the JAR. The property is supported with both the Maven and Gradle plugins.


1 Answers

1) One example of running a Spring Boot app in non-production mode (i.e. not from the JAR) is from an IDE (most specifically Eclipse or IntelliJ), where you can launch the application from the main method, or using the Spring Boot launch support. This is the most practical use of Dev Tools as it allows to continuously watch the changes in your application without restarting.

2) excludeDevTools is an option of the Spring Boot Maven Plugin http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/maven-plugin/repackage-mojo.html or the Gradle plugin - see http://docs.spring.io/spring-boot/docs/current/reference/html/build-tool-plugins-gradle-plugin.html#build-tool-plugins-gradle-repackage-configuration.

So in your case it would be bootRepackage { mainClass = 'demo.Application' excludeDevtools = true }

like image 157
Marius Bogoevici Avatar answered Oct 09 '22 11:10

Marius Bogoevici