2017-02-19 73 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你能否确认你的视图是否被调用? –