且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Spring Boot devtools IntelliJ

更新时间:2022-10-14 22:43:29

我最近有同样的问题。问题在于devtools拦截变化的方式。默认情况下,等待编译完成1秒钟。如果classpath在那段时间之后不存在,那么devtools会认为class已被删除,并在没有它的情况下重新启动应用程序。

Groovy在我的机器上完成编译过程的平均时间大约需要3秒。因此,类重新启动时被删除。



此问题的解决方案是在应用程序中设置 spring.devtools.restart.pollInterval 属性.properties 文件的值大于1000(对于我,4000可以正常工作)。


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?

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).