Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Boot devtools IntelliJ

I am using Spring Boot 1.3.0.M5 and I am trying to take advantage of devtools. This allows you to make changes to your application while in development and boot will reload your application. I have seen this demo work in STS using Java and Maven.

I am trying to use Groovy & Gradle in IntelliJ 14.1 and I am having some issues. First here is my Gradle Build dependencies.

dependencies {
    compile("org.springframework.boot:spring-boot-devtools")
    compile("org.springframework.boot:spring-boot-starter-web")
    compile("org.codehaus.groovy:groovy")
    testCompile("org.springframework.boot:spring-boot-starter-test") 
}

I created a controller with a mapping for "/"

package demo

import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController

@RestController
class HomeController {

    @RequestMapping("/")
    public String home(){
        "Hello, SpringOne 2GX!"
    }

}

I am able to run the application and visit http://localhost:8080 and see the string print to the screen. If I make a change to the file nothing happens because IntelliJ does not compile on change. If you go to Build > Make Project though I can see Spring Boot in the console reload. So this seems to be working but if I go back to the root URL I get the following error which is basically what you would see if you had no controllers in place.

Whitelabel Error Page

This application has no explicit mapping for /error, so you are seeing this as a fallback.

Thu Sep 17 10:43:25 EDT 2015 There was an unexpected error (type=Not Found, status=404). No message available

Anyone know why the reload is not working correctly for me?

like image 613
Dan Vega Avatar asked Sep 17 '15 14:09

Dan Vega


1 Answers

I had the same issue recently. The problem is in the way devtools intercepts changes. By default it waits for 1 second for compiling to be finished. If class doesn't exist on classpath after that time then devtools consider class was deleted and restart application without it.

Most times it takes 3 second in average for groovy to finish compilation process on my machine. Therefore class getting removed while restart.

The solution for this issue is to set spring.devtools.restart.pollInterval property in application.properties file to value greater than 1000 (for me 4000 works fine).

like image 163
Ilya Fedorov Avatar answered Oct 07 '22 21:10

Ilya Fedorov