1

I'm following the example in Spring in Action 4th edition, Chapter 5 and running the Spittr example app.

When making any request, but for this question specifically:

http://localhost:8080/

I get the following error:

This application has no explicit mapping for /error, so you are seeing this as a fallback.

There was an unexpected error (type=Internal Server Error, status=500). Error resolving template "home", template might not exist or might not be accessible by any of the configured Template Resolvers.

I've looked at: This application has no explicit mapping for /error where the solution was to have the main class at the top of the package hierachy. I've tried this without any success.

Here's the code:

SpittrApplication.java

package spittr;

@SpringBootApplication
public class SpittrApplication {

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

HomeController.java

package spittr.web.controller;

@Controller
@RequestMapping("/")
public class HomeController {

  @RequestMapping(method = GET)
  public String home(Model model) {
    return "home";
  }

}

The template is under src/main/webapp/WEB-INF/views/home.jsp

The console logs the following error:

Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.thymeleaf.exceptions.TemplateInputException: Error resolving template "home", template might not exist or might not be accessible by any of the configured Template Resolvers] with root cause

Khei
  • 73
  • 3
  • 11
  • 1
    The error message talks about Thymeleaf. But you apparently want to use JSPs (although they're discouraged). Have you read https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-features-spring-mvc-template-engines? Have youread https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-features-jsp-limitations? – JB Nizet Apr 07 '18 at 12:56
  • @JB Nizet yes you're right, I blindly copied the book's code without noticing I was mixing JSPs with Thymeleaf view resolvers. Thanks. – Khei Apr 08 '18 at 00:50
  • You may not be handling a mapping for `/` when the app executes. Maybe you are missing the HomeController with a mapping for @GetMapping("/") public String welcome() { return "" + "

    Welcome to Spring & MongoDB & REST

    " + ""; }`. Make sure you have the structure mentioned here: https://stackoverflow.com/a/39017839/2414129
    – ColinWa Oct 10 '21 at 16:52

0 Answers0