How does Spring Boot load changes in code without restarting the server?
Asked Answered
M

6

22

In a Spring Boot application, if you make change in your code, is it possible to see them without restarting the server? If yes, how can that be achieved?

Monetta answered 10/7, 2017 at 18:4 Comment(0)
H
24

Add spring-boot-devtools module to your project, which includes LiveReload server which can be used to trigger a browser refresh whenever a resource has been changed.You can download browser extensions from livereload.com.

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
    </dependency>
</dependencies>
Hierocracy answered 10/7, 2017 at 18:26 Comment(0)
G
7

You only need to add spring-boot-devtools dependency in your 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
Gaynor answered 27/8, 2019 at 5:46 Comment(0)
N
4

See the Spring Boot Developer Tools.

Notice:

  1. When you change your Java code, the server need to be restarted. The Spring Boot Developer Toolsjust help you to reload it

  2. If it is jsp, then you do not have to restart server.

Nehemiah answered 10/7, 2017 at 18:8 Comment(0)
T
2

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> 
Tho answered 24/5, 2021 at 2:36 Comment(3)
Good answer :) But it's not related to IntelliJ , it's a maven plugin for spring boot developmentQuinary
Thank you for the comment, really cool to know that's a solution independent on IDE, I've actually been curious why fg78nc's anwser didn't work for me, any idea what's the effect of tag <scope>runtime</scope> <optional>true</optional> in this context?Tho
Actually, even with this dependency, hot reloading may not working on IntelliJ out-of-the-box. So, the full solution may also depend on the IDE you're using.Clarence
A
1

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

Aforetime answered 29/6, 2022 at 12:8 Comment(0)
C
0

Just enable Build Automatically in the Project tab in STS, if you have the dependency in your pom.xml

Collbaith answered 13/4, 2023 at 7:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.