0

In my Spring Boot (2.6.4) project I would like to know if it is possible to make changes to a class (for example entity, DTO or controller) and have the changed classes reload without having to restart the whole application (like here)

My environment consists of: IDE: Intellij Idea 2023 Ultimate Build Tool: Gradle

I have enabled the options in Intellij for:

  • Settings->Build, Execution, Deployment->Compiler : Build Project Automatically (ticked)
  • Enabled option 'allow auto-make to start even if developed application is currently running' in Settings -> Advanced Settings under compiler

In gradle I have tried both options:

developmentOnly 'org.springframework.boot:spring-boot-devtools'
and
compileOnly 'org.springframework.boot:spring-boot-devtools'

I am Debugging the project in Intellij using the Green Debug icon on the tool menu.

I then tried to make a change to a Dto class while running the project in Debug, for example:

@NoArgsConstructor
@AllArgsConstructor
@Getter
@Setter
public class CarDto {
    @JsonProperty("carId")
    private Long carId;
    @JsonProperty("name")
    private String name;
}

By commenting out the two lines:

//@JsonProperty("name")
//private String name;

But there is no indication on the terminal in Intellij that it has detected the changes and reloaded the changed classes.

UPDATED

Another more recent post states that it is controlled by the run configuration in Intellij.

It states:

  1. Install Spring Boot Developer tools;
  2. Set the On Update Action in Run Configuration to Hot swap classes and update trigger file if failed
  3. On Frame deactivation have the class `Update Classes and Resources'

enter image description here

Q: How can I get the live reload to work - it appears there is a few different sets of instructions.

I can post more of the build.gradle if needed.

Radika Moonesinghe
  • 361
  • 2
  • 6
  • 17
  • To avoid a server restart on each change you could try to get rid of `spring-boot-devtools` dependency and hotswap changes as per https://stackoverflow.com/a/61416076/12844632 Notice that there are some known hotswap limitations https://www.jetbrains.com/help/idea/altering-the-program-s-execution-flow.html#limitations – Egor Klepikov Aug 07 '23 at 09:26

1 Answers1

1

Are you just changing the classes while debugging, or are you you planning to update the application on a running server. Intellij has had hot-reload, 10+ years before Spring boot was invented, so I personally don't use spring-boot-devtools, just start the application in the debugger and, do shit+F9 (old hotkey) to recompile and reload the classes of the JVM.

Klaus Groenbaek
  • 4,820
  • 2
  • 15
  • 30
  • This is all local for development. During development Tomcat is running. I am changing classes - for example DTO as per above. – Radika Moonesinghe Aug 05 '23 at 02:14
  • I have worked with Intellij since 2003, I don't remember a time where you could not hot reload classes in the debugger :). Just recompile and Intellij will have the JVM reload the changed class files. – Klaus Groenbaek Aug 05 '23 at 03:35