I am attempting to get Freemarker views displaying with Spring Boot for the first time, and currently get the following error in the browser:
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Sun Feb 19 17:59:07 GMT 2017 There was an unexpected error (type=Not Found, status=404). No message available
I am using Spring Boot 1.5.
My file structure:
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
Server
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);
}
}
Why is Spring unable to resolve the loginPage.ftl view? Why can't I see it in the web browser?
Spring Boot recently yet again introduced a breaking change, which leads to the infamous whitelabel error
page. They changed the default suffix from .ftl
to .ftlh
.
https://github.com/spring-projects/spring-boot/issues/15131
So for Spring Boot 2.2.x applications, these extensions have to be updated.
With Spring Boot 1.5.1, you don't need to add those properties to your application.properties file, they're already defined, thanks to autoconfiguration.
Remove those 2 properties and it should work with the following dependencies in your 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>
Documentation can be found here: http://docs.spring.io/spring-boot/docs/1.5.1.RELEASE/reference/htmlsingle/#boot-features-spring-mvc-template-engines
Your freemarker template directory settings inside application.properties
is wrong. It should be:
spring.freemarker.template-loader-path=classpath:/templates/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With