I created a Spring Boot Application using Spring Initilizr. I then included Apache's Freemarker
template engine to load the templates from my project. The engine by default loads templates from: src/main/resources/templates/
folder.
I am trying to load a simple index.ftl
file as template when the user visits the webpage http://localhost:8080
. But I need to load the templates from src/main/webapp/
folder. Whenever I try to load the templates from outside the resources
folder, the template engine fails to find the templates.
I have gone through various tutorials and Stack Overflow questions. None answer my question and I'm stuck with a 404 ERROR
because the engine is not able to find the files.
The file structure is:
|-src
|---main
|-----java
|-------MainApplication.java
|-------controllers
|---------ViewController.java
|-----resources
|-------static
|-------templates
|-------application.properties
|-----webapp
|-------index.ftl
After a lot of digging, I came across a post where they suggested changing the location where the template engine searches the files. It suggested adding following lines in application.properties:
spring.freemarker.enabled=true
spring.freemarker.template-loader-path=classpath:src/main/webapp/
This doesn't seem to work at all.
I am trying to resolve simple index page when I visit the webpage at http://localhost:8080. I've written following code for mapping the HTTP request in ViewController.java
:
@RequestMapping("/")
public ModelAndView home(Model model)
{
return new ModelAndView("index");
}
No idea if I am totally getting it wrong or I've missed some configuration.