How does Spring Boot load changes in code without restarting the server

Viewed 24419

This was an interview question to me that , is it possible that some changes you made in your code and it is an spring boot application, and without restarting the server you are able to get those changes.? if yes, then how is it possible in spring boot.

I want to know that how is it possible in Spring Boot.?

5 Answers

You only need to add devtool dependency in pom.xml and yml file property:

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

# for not restarting the server every time
spring.devtools.restart.enabled:  false

I'm using intellij, the follow dependency setting works for me.

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

Try the following steps and it should work

  1. Add the following to pom.xml

    <dependency>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-devtools</artifactId>       
             <optional>true</optional>
         </dependency>
    
  2. In application.properties

    spring.devtools.restart.enabled=true

Note : Ensure spring boot is restarted once after making changes to the application.properties file.

For additional information please check https://docs.spring.io/spring-boot/docs/1.5.16.RELEASE/reference/html/using-boot-devtools.html

Related