2015-09-17 58 views
5

我使用的是Spring Boot 1.3.0.M5,我試圖利用devtools。這使您可以在開發過程中對應用程序進行更改,並可以重新加載應用程序。我已經在使用Java和Maven的STS中看到了這個演示工作。Spring Boot devtools IntelliJ

我想在IntelliJ 14.1中使用Groovy & Gradle,我遇到了一些問題。首先這裏是我的Gradle Build依賴關係。

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") 
} 

我創建了一個映射控制器「/」

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!" 
    } 

} 

我能夠運行應用程序和訪問http://localhost:8080和看到字符串打印到屏幕上。如果我對文件進行更改,則不會發生任何事情,因爲IntelliJ不會在更改時編譯。如果你去Build> Make Project,雖然我可以在控制檯重新加載中看到Spring Boot。所以這似乎是工作,但如果我回到根URL我得到以下錯誤,這基本上是你會看到,如果你沒有控制器的地方。

白色標籤錯誤頁面

該應用對/錯誤沒有明確的映射,所以你看到 此作爲後備。

Thu Sep 17 10:43:25 EDT 2015有一個意外的錯誤(type = Not Found,status = 404)。沒有留言可用

任何人都知道爲什麼重新加載不能正常工作嗎?

+0

如果你運行一個'gradle classes',它會工作嗎? – cfrick

+0

@cfrick沒有相同的問題。 Spring Boot重新加載並且出現白色標籤錯誤。 – cfaddict

+0

,你用'gradle bootRun'運行這個? – cfrick

回答

5

我最近有同樣的問題。問題在於devtools攔截變化的方式。默認情況下,等待編譯完成1秒鐘。如果classpath在那段時間之後不存在,那麼devtools會認爲class已被刪除,並在沒有它的情況下重新啓動應用程序。

Groovy在我的機器上完成編譯過程的平均時間大多數需要3秒。因此,類重新啓動時刪除。

此問題的解決方法是設置spring.devtools.restart.pollInterval財產application.properties文件價值大於1000(對我來說4000正常工作)。

0

如果您指定要掃描的確切軟件包,這將是確定的。如:

@ComponentScan(basePackages = "com.lsj.web") 
@EnableAutoConfiguration 
public class PlatformApplication { 

    public static void main(String[] args) throws Exception { 
     SpringApplication.run(PlatformApplication.class, args); 
    } 
} 
相關問題