Spring boot

Spring boot devtools dependency

Spring boot devtools dependency maven

Spring Boot includes an additional set of tools that can make the application development experience a little more pleasant.

By configuring spring-boot-devtools starters in pom.xml or build.gradle will automatically restart the container whenever files on the classpath change.

This can be a useful feature when working in an IDE like eclipse, as it gives a very fast feedback loop for code changes.

When working with eclipse IDE make sure project -> build automatically option is checked.

If you are using the browser as a client, then you can add live reload plugin to reload the browser whenever the container restarts

Configure pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>

	<groupId>com.candidjava.spring.boot</groupId>
	<artifactId>helloworld</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<name>helloworld-dev-tool</name>
	<url>http://maven.apache.org</url>
	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>2.0.4.RELEASE</version>
	</parent>
	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<java.version>1.8</java.version>
	</properties>

	<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>
		
		<!--  Developer tool devtools -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-devtools</artifactId>
			<optional>true</optional>
		</dependency>
	</dependencies>

	<build>
		<plugins>
			<!-- Package as an executable jar -->
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
			</plugin>
		</plugins>
	</build>
</project>

Launch Spring boot application (Example.java)

Launch this as a spring boot application and hit http://localhost:8080/ and make some changes in the code, you will notice that console will automatically restart the container with changes. Live reload plugin in the browser will automatically refresh the browser page.

package com.candidjava.spring.boot.helloworld;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@SpringBootApplication
public class Example {

 @RequestMapping("/")
 String home() {
  return "Hello candid welcome";
 }

 public static void main(String[] args) throws Exception {
  SpringApplication.run(Example.class, args);
 }

}

Download

Download source code from my github account Click here