Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Boot app deployed to Heroku doesn't locate its' thymeleaf views

My Spring Boot app runs perfectly at localhost but when I'm deploying it to Heroku, my app's controller stops seeing the views which are normally located at /templates/ directory. Why does this happen? How can I be sure that heroku actually uploads and compiles my views? If it does, should I change actual values of @RequestMapping of my @Controller class in order to make them reachable when they are at heroku?

You can find my whole working webapp here: https://github.com/slavicketernity/testik56

Here is my uploaded and runnung app: https://testik56app.herokuapp.com/login

like image 290
Václav Avatar asked Jun 01 '17 13:06

Václav


People also ask

How do I enable Thymeleaf in spring boot?

Spring Boot will provide auto-configuration for Thymeleaf. Add spring-boot-starter-thymeleaf dependency in pom. xml to enable this auto-configuration. No other configurations required, Spring Boot will inject all required configuration to work with Thymeleaf.

Is Thymeleaf view resolver?

The ViewResolver interface in Spring MVC maps the view names returned by a controller to actual view objects. ThymeleafViewResolver implements the ViewResolver interface, and it's used to determine which Thymeleaf views to render, given a view name.

Is Thymeleaf fully integrated with Spring?

It provides full integration with Spring Framework. It applies a set of transformations to template files in order to display data or text produced by the application. It is appropriate for serving XHTML/HTML5 in web applications. The goal of Thymeleaf is to provide a stylish and well-formed way of creating templates.


1 Answers

In my case it was fault of the slashes on the beginning of the String returned by Controller's method with template location.

After I changed the String returned by controller's methods from

@RequestMapping(value = "/orders/{orderId}/create_entry")
String create(@PathVariable String orderId) {
    return "/order_entries/create";
}

to

@RequestMapping(value = "/orders/{orderId}/create_entry")
String create(@PathVariable String orderId) {
    return "order_entries/create";
}

then it started to work.

like image 50
konkit Avatar answered Nov 08 '22 13:11

konkit