2016-12-24 22 views
0

我有一個具有reactjs的彈簧啓動應用程序。我面臨的問題不是重定向到根路徑。 我有一個控制器(最簡單的事情),它有一個映射到根路徑(「/」)的方法。沒有重定向到index.html文件夾內的靜態資源(pubilc彈簧啓動)

而且,我已將index.html放置到所有位置,即公用文件夾/靜態文件夾和模板文件夾。

但是當我導航到http://localhost:8080/那麼它將進入錯誤頁面。

鏈接如下: - https://spring.io/guides/tutorials/react-and-spring-data-rest/

甚至嘗試: - Can't serve static index.html with Spring Boot

我有一個版本1.3.5.RELEASE 「彈簧引導起動網」 的依賴。

回答

1

請確保您已經添加Thymeleaf到你的依賴:

<dependency> 
    <groupId>org.springframework.boot</groupId> 
    <artifactId>spring-boot-starter-thymeleaf</artifactId> 
</dependency> 

然後,您可以輕鬆地從你的控制器返回index.html模板(放在resources/templates/):

@RequestMapping(value = "/") 
public String index() { 
    return "index"; 
}