Newsletter

Spring Boot – How to Reload Changes Without Restarting the Server

Spring-Boot-Tutorials » on Dec 8, 2017 { 8 Comments } By Sivateja

One of the main challenge for the java developers is to deploy the apps and restart server when ever there is a code change. In this article, I am going to show you how to reload the code changes without having to restart the server. In Spring Boot this can be achieved by adding a DevTools module, just add the following dependency in your Spring Boots pom.xml and build it. 

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

Spring Boot DevTools module does exactly what developers needed, this eliminates the process of manually deploying the changes. DevTools will auto restart the server when we have changes. Spring team they haven’t included this feature in Spring Boot’s initial version, upon several request they added this feature later.

Final pom.xml looks like

<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.java4s</groupId>
  <artifactId>SpringBootDevTools</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  
  	<parent>
	    <groupId>org.springframework.boot</groupId>
	    <artifactId>spring-boot-starter-parent</artifactId>
	    <version>1.5.6.RELEASE</version>
	</parent>
	
	<dependencies>
	    <dependency>
	        <groupId>org.springframework.boot</groupId>
	        <artifactId>spring-boot-starter-web</artifactId>
	    </dependency>
	    <dependency>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-devtools</artifactId>
		<optional>true</optional>
	     </dependency>
	</dependencies>
	
	<properties>
	 <java.version>1.8</java.version>
	</properties> 
  
</project>

You can start the server and run the application. Now if you do some code changes to your project files, you no need to restart the server again to view the changes rather just refresh your browser 😉 that’s it.

Hope your enjoy this article, you can download the complete example by clicking on download button.

​​

You Might Also Like

  ::. About the Author .::

Java4s_Author
Sivateja Kandula - Java/J2EE Full Stack Developer
Founder of Java4s - Get It Yourself, A popular Java/J2EE Programming Blog, Love Java and UI frameworks.
You can sign-up for the Email Newsletter for your daily dose of Java tutorials.

Comments

8 Responses to “Spring Boot – How to Reload Changes Without Restarting the Server”
  1. sundip says:

    super mama . chala help avtondi.

  2. Swapna says:

    But it didn't reflected in my application even I refreshed the browser.

  3. jagan says:

    Hi Siva,

    I have read the Spring Boot Article its was very Nice

    But I have a small doubt,spring BOOT provided inbuilt server like tomcat, GlassFish etc
    so,spring boot application move to production server there we are using different application server ,like WebLogic some diff, any changes in need do to in spring Boot or not?

  4. Sudhir says:

    One of the best site for learning Spring Boot I got. I really enjoying after learning all the pages.

    It a fantastic tutorial.As a spring MVC developer , I can understand how spring boot made life easy.

    Great work dude.
    All the best for you.

  5. Anthony says:

    Hey Team, I actuallly know the behaviour of dev tools spring boot dependency jar. It tries to keep on restrating the server as soon as changes are made in any callpath file or application .properties file. But my question here is i dont to restart the server, but changes need to be deployed. Which is not working with the thing you provide above. Please correct me if am wrong.

    Thanks in advance.

  6. Mareswara Rao says:

    Hi Siva,

    Im getting below error while running the application(run>java application) after adding devtoools dependency in pom.xml

    Exception in thread "main" java.lang.ClassCastException: class jdk.internal.loader.ClassLoaders$AppClassLoader cannot be cast to class java.net.URLClassLoader (jdk.internal.loader.ClassLoaders$AppClassLoader and java.net.URLClassLoader are in module java.base of loader 'bootstrap')
    at org.springframework.boot.devtools.restart.DefaultRestartInitializer.getUrls(DefaultRestartInitializer.java:93)
    at org.springframework.boot.devtools.restart.DefaultRestartInitializer.getInitialUrls(DefaultRestartInitializer.java:56)
    at org.springframework.boot.devtools.restart.Restarter.<init>(Restarter.java:140)
    at org.springframework.boot.devtools.restart.Restarter.initialize(Restarter.java:546)
    at org.springframework.boot.devtools.restart.RestartApplicationListener.onApplicationStartingEvent(RestartApplicationListener.java:67)
    at org.springframework.boot.devtools.restart.RestartApplicationListener.onApplicationEvent(RestartApplicationListener.java:45)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:167)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:122)
    at org.springframework.boot.context.event.EventPublishingRunListener.starting(EventPublishingRunListener.java:69)
    at org.springframework.boot.SpringApplicationRunListeners.starting(SpringApplicationRunListeners.java:48)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:292)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107)

  7. madhu says:

    This feature is not working in my local

Name*
Mail*
Website



By posting your answer, you agree to our comments policy.
Most Recent Posts from Top Categories
Spring Boot Hibernate Spring
Contact | About Us | Privacy Policy | Advertise With Us

© 2010 - 2024 Java4s - Get It Yourself.
The content is copyrighted to Sivateja Kandula and may not be reproduced on other websites.