Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Spring Boot DevTools

Definition of Spring Boot DevTools

Spring devtool is nothing but the developer’s tool which helps the developers to improve the time when we work with Spring boot application, it is come with spring 1.3 release, it basically takes the current changes which we make into the application and restart the server which turns help in improving the development process and provide a better development environment for developers. To use this we need to add spring-boot-devtools in our project.

Syntax:

For Gradel :
configurations {
developmentOnly
runtimeClasspath {
extendsFrom developmentOnly
}
}
dependencies {
developmentOnly("org.springframework.boot:spring-boot-devtools")
}
For Maven :


org.springframework.boot
spring-boot-devtools
true

Functions of Spring Boot DevTools

It provides us many features which works differently like they can restart our application with all necessary changes, deployment on to the cloud, provides embedded server as well and etc. which makes the development easy and not time-consuming.

If we include the spring boot dev tool dependency into our project so start working and configure so many activities for us which helps us to reduce the time needed to run the application. These things are very much important when we are developing our application thus provide us with improving timing. Like we do not need to build war and jar by automatic restart it does its job, also we can debug and update our application which is at cloud hence making easy to manage and maintain. For this dev tools to enable into our application we do changes in the following:

  • In property file
  • pom.xml
  • make one new file with . prefix.

Example of Spring Boot DevTools

To build an example in spring boot follow the below steps: we need to add the dependency for dev tool into pom.xml while creating the project or it can be added further:

Code:



org.springframework.boot
spring-boot-devtools
true

Now open spring initializer and create a project. Go to the main java class and run the project. It will show something like the below output.

Java Class:

package com.example.test.demotest;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;
import com.example.test.config.JwtFilter;
@SpringBootApplication
public class DemoTestApplication extends SpringBootServletInitializer{
public static void main(String[] args) {
SpringApplication.run(DemoTestApplication.class, args);
}
}

Output:

Features

spring boot provides us many features to debug, build, start our application. It also provides support for disabling and enable these developer’s tools into our application just by setting the property value to true or false into the property file. Features of developers tool are described below in details :

1. Remote Application

This feature includes a remote change that can be done efficiently over the network b the use of HTTP like we can debug our code and also we can update the files if any changes made. In the remote application, we have two types.

  • Remote debugging
  • Remote update
Remote Debugging

In remote debugging, we can debug our remote applications on the network by using HTTP. Also to use this we need to have a dev tool in our spring boot application as enabled.

  • Enable the Debug Port: Xdebug -Xrunjdwp:server=y,transport=dt_socket,suspend=n
  • Override the Default Port: spring.devtools.remote.debug.local-port=8010
Remote Update

If we make any change into our application so this feature just restarts the application. It continuously monitors our application if any changes occur in the classpath. So it just updates the remote resources and restarts the server. But for this, we do not need to stop the server all the changes are done when the remote server is running and up. It also provides us loggers statement.

2. Automatic Restart

So this feature of spring boot provides an automatic restart of the server whenever any change detected in files. so we do not need to manually build our code and deploy the war file all these things are managed by spring boot itself but for this, we need to use this dev tool package into our project. This feature can we well uses with live reload which we will discuss in the next point. we have gradel and maven as default build in a plugin.

we can restart our application by using the maven and gradel support we have.

make some configuration as:

  • pringApplication.setRegisterShutdownHook(false)
  • We can also disable the restart, spring.devtools.restart.enabled= false into the property file. or else we can also set this into our main() java class like below:

Syntax:

package com.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@SpringBootApplication
public class TvvApplication {
public static void main(String[] args) {
System.setProperty("spring.devtools.restart.enabled", "false");
SpringApplication.run(TvvApplication.class, args);
}
}

3. Property Default

It is stated that the spring boot application uses a cache to provide better performance. But in production spring boot dev tool disables this caching features. To configured cache into spring boot application, we need to make an entry in the application.property file. but this dev tool feature will apply some configuration automatically. So by this, we do not need to reload our template files again and again.

4. Global Settings

To enable this global setting into our project we need to add one file into our home folder path. This file name will always start from a dot(.).

file name is .spring-boot-devtools.properties. so by adding this file globally, we apply this feature to all applications on our matching those who have dev tools packages enable in their projects. spring.devtools.reload.trigger-file=.reloadtrigger

5. LiveReload

This spring boot feature includes one embedded server which helps us to refresh the browser whenever we make any change. so whenever we make a change and go to the browser we will always going to have refresh data as we have in angular also. But sometimes we do not want this feature to enable our application so we can set this to: ing.devtools.livereload.enabled = false into a property file.

Recommended Articles

This is a guide to Spring Boot DevTools. Here we discuss the Introduction and spring boot devtools features along with an example and its code implementation. You may also have a look at the following articles to learn more –

  1. Spring Boot Annotations
  2. Spring Boot Versions
  3. Spring Boot Feature
  4. Spring Boot Application

The post Spring Boot DevTools appeared first on EDUCBA.



This post first appeared on Best Online Training & Video Courses | EduCBA, please read the originial post: here

Share the post

Spring Boot DevTools

×

Subscribe to Best Online Training & Video Courses | Educba

Get updates delivered right to your inbox!

Thank you for your subscription

×