2017-02-19 51 views
1

我試圖讓Freemarker的意見和春天開機顯示首次,目前在瀏覽器中出現以下錯誤:春天開機無法解決的Freemarker視圖

白色標籤錯誤頁面

這應用程序沒有明確映射/錯誤,因此您將此視爲 作爲後備。

Sun Feb 19 17:59:07 GMT 2017有一個意外的錯誤(type = Not Found,status = 404)。沒有留言可用

我正在使用Spring Boot 1.5。

我的文件結構:

enter image description here

的LoginController

package com.crm.controller; 

import org.springframework.beans.factory.annotation.Autowired; 
import org.springframework.stereotype.Controller; 
import org.springframework.web.bind.annotation.RequestMapping; 

import com.crm.service.LoginService; 

@Controller 
public class LoginController { 

    @Autowired 
    private LoginService loginService; 

    @RequestMapping("/login") 
    public String authenticate() { 
     return "loginPage"; 
    } 
} 

application.properties

spring.freemarker.template-loader-path:/
spring.freemarker.suffix: .ftl 

服務器

package com.crm; 

import org.springframework.boot.SpringApplication; 
import org.springframework.boot.autoconfigure.SpringBootApplication; 

@SpringBootApplication 
public class Server{ 

    public static void main(String[] args) { 
     SpringApplication.run(Server.class, args); 
    } 
} 

爲什麼Spring無法解析loginPage.ftl視圖?爲什麼我無法在網絡瀏覽器中看到它?

回答

2

藉助於Spring 1.5.1引導,你不需要這些屬性添加到您的application.properties文件,他們已經確定,這要歸功於自動配置。

刪除的2個屬性,它應該在你的pom.xml以下依賴性工作:

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

文檔可以在這裏找到:http://docs.spring.io/spring-boot/docs/1.5.1.RELEASE/reference/htmlsingle/#boot-features-spring-mvc-template-engines

+0

如果您使用spring-security像我用來處理登錄頁面和Thymeleaf/FreeMarker一樣,請確保將@EnableWebSecurity添加到您的配置中,以便正確解析資源 – rdlopes

+1

正如上面的鏈接所述。模板引擎不在'src/main/java/resources/templates'中查找'src/main/resources/templates'。 – crm

2

application.properties裏面的你的freemarker模板目錄設置是錯誤的。它應該是:

spring.freemarker.template-loader-path=classpath:/templates/ 
+0

我想你的意思'application.properties'文件而不是'application.xml'文件。 –

+0

該更改尚未解決。 – crm

+0

@crm你能否確認你的視圖是否被調用? –