John Little
John Little

Reputation: 12403

can spring auto reload changes like grails?

One of the main benefits of grails, which is based on Spring, is that you dont need to rebuild and re-run the entire application (which takes minutes) each time you change a line of code, it just recopiles that one file and auto-loads the changes.

Following this tutorial:

https://spring.io/guides/gs/spring-boot/

To run the app, you have to use the command line and do this outside of intellij:

./gradlew build && java -jar build/libs/gs-spring-boot-0.1.0.jar

If you change a line of code, e.g. in a controller, you have to kill the application, rebuild it and restart it, which takes a while.

I came across something called automatic restart in dev tools. Is this something to do with auto-reloading of changes, and if so, how is it used?

Upvotes: 2

Views: 3365

Answers (2)

Combine
Combine

Reputation: 4224

Based on the @Ken Chan answer but very briefly

For Eclipse - click in the menu "Project" -> select "Build Automatically"

In my case I was running some spring boot server - I had to stop the server, enable "Build Automatically" like on the picture, then start the server again and on every change - the code recompiled.

enter image description here

Upvotes: 2

Ken Chan
Ken Chan

Reputation: 90497

If a class is changed , I am sorry that Spring boot devtools will not just reload that changed classes but it will restart the whole application automatically . But this restart should be faster than the normal cold start based on what the docs said :

The restart technology provided by Spring Boot works by using two classloaders. Classes that do not change (for example, those from third-party jars) are loaded into a base classloader. Classes that you are actively developing are loaded into a restart classloader. When the application is restarted, the restart classloader is thrown away and a new one is created. This approach means that application restarts are typically much faster than “cold starts”, since the base classloader is already available and populated.

If you need to just reload the changed classes , you may consider to use JRebel which is not free.

To use spring boot devtools , just includes its dependency and then start the application as usual using IDE.

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

It will the monitor the classpath folders and then restart the application if there are any changes in these folders.

In case of Eclipse , what you need is to ensure Project ➡️ Build Automatically is selected. Once the source codes are changed , Eclipse will then just compiled that changed sources codes to the classes in the classpath folders automatically which trigger devtools to restart the application.

Upvotes: 8

Related Questions