Spring Boot gives "TemplateInputException: Error resolving template" when running from jar

spring boot tutorialspoint
spring boot wiki
spring boot javatpoint
spring boot documentation
spring application
spring boot interview questions
spring boot 2 tutorial
spring boot actuator

I have an app that works perfectly when started within IntelliJ or via gradle bootRun.

however, if I do gradle bootRepackage and then try and run the resulting jar, I end up with:

2014-12-02 21:46:14.086 ERROR 9839 --- [nio-2014-exec-2] org.thymeleaf.TemplateEngine             : [THYMELEAF][http-nio-2014-exec-2] Exception processing template "/login": Error resolving template "/login", template might not exist or might not be accessible by any of the configured Template Resolvers
2014-12-02 21:46:14.087 ERROR 9839 --- [nio-2014-exec-2] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.thymeleaf.exceptions.TemplateInputException: Error resolving template "/login", template might not exist or might not be accessible by any of the configured Template Resolvers] with root cause

org.thymeleaf.exceptions.TemplateInputException: Error resolving template "/login", template might not exist or might not be accessible by any of the configured Template Resolvers
    at org.thymeleaf.TemplateRepository.getTemplate(TemplateRepository.java:245)
    at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1104)
    at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1060)
    at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1011)
    at org.thymeleaf.spring4.view.ThymeleafView.renderFragment(ThymeleafView.java:335)

I can see that the jar has /templates/** contained in it. the content looks OK to me.

One possible(?) factor may be that I use an html page referring to a layout, thus:

  layout:decorator="layouts/main"

I can confirm that the file IS in the jar.

/login is defined thusly:

@Override
public void addViewControllers(ViewControllerRegistry registry) {
    registry.addViewController("/login").setViewName("/login");
    registry.addViewController("/").setViewName("/login");
}

and I have spring security configured as:

@Configuration
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

@Override
public void configure(WebSecurity security) {
    security.ignoring().antMatchers("/assets/**");
}

@Override
protected void configure(HttpSecurity http) throws Exception {
    http
            .csrf().disable();
    http
            .authorizeRequests()
            .antMatchers("/").permitAll()
            .anyRequest().authenticated();
    http
            .formLogin()
            .loginPage("/login")
            .defaultSuccessUrl("/home")
            .failureUrl("/login?error")
            .permitAll()
            .and()
            .logout()
            .invalidateHttpSession(true)
            .logoutSuccessUrl("/login?logout")
            .permitAll();
}
}

I think that's all that might be relevant to this issue...

I have seen https://github.com/spring-projects/spring-boot/issues/112 and Proper location of Thymeleaf views for Spring (amongst others). These resources notwithstanding, I have not been successful at getting template resolution working.

Any suggestions gratefully recieved.

To have come so far with Spring Boot yet to have stumbled at the last hurdle (near-final deployment) is vexatious.

I had same problem using spring boot with thymeleaf by default configuration. All worked until I have to try .jar

message says: ... org.thymeleaf.exceptions.TemplateInputException: Error resolving template "/fragments/footer"

I solved playing with / , problem was that they don't need the slash.

I Changed this:

<footer class="footers" th:replace="/fragments/footer :: footer">

for this:

<footer class="footers" th:replace="fragments/footer :: footer">

Getting Started, This will give you two starter classes, Application.java, and ApplicationTests.java Here is the Application.java class that Spring Boot provides: Why Spring Boot? It provides a flexible way to configure Java Beans, XML configurations, and Database Transactions. It provides a powerful batch processing and manages REST endpoints. In Spring Boot, everything is auto configured; no manual configurations are needed. It offers annotation-based

The answer seems to be here: https://github.com/spring-projects/spring-boot/issues/1744

In a nutshell: if a resouce path contains '//', things go awry.

The fix is to modify application.yml thusly:

spring:
  thymeleaf:
    prefix: classpath:/templates

(the fix is similar for a .properties file, of course)

The knock-on effect is that all references to templates or whatever need to be preceeded by a slash, as in (Thymeleaf .html file):

      layout:decorator="/layouts/main"

or (Groovy controller):

@RequestMapping(value = "/home", method = RequestMethod.GET)
def home(Model model, Principal principal) {

    "/home/home"
}

I think that spring boot should fix this. Urgently. This is REALLY bad ergonomics that blows up badly, just at the point where one feels like one is nearing final deployment.

Deploying Spring Boot Applications, Spring framework provides flexibility to configure beans in multiple ways such as XML, Annotations, and JavaConfig. With the number of features  We are using spring boot to develop a REST application that we will be deploying on JOnAS 5.x which is a servlet 2.5 container. We used Spring Boot Legacy taking help from spring documentation. The

Okay, I found where you have to take a close look. In your Controller classes, when you use @RequestMapping on class, no leading slash (e.g. @RequestMapping("property")). On Method you need a leading slash (e.g. @GetMapping("/list")) and the return value no leading slash (e.g. return "property/list";)

An Example Snippet

@Controller
@RequestMapping("property")
public class PropertyController {
    @NonNull PropertyService service;

    @GetMapping("/list")
    public String list() {
        return "property/list";
    }
}

Why Spring Boot?, Spring Boot provides a good platform for Java developers to develop a stand-​alone and production-grade spring application that you can just run. You can get​  Everything was working fine. We now want to deploy the API in a separate development environment which has a couple of other (non-Spring) applications running on a Tomcat container. I made the changes specified in Converting a Spring Boot JAR Application to a WAR using Maven and Spring Boot Docs.

I faced the issue when using the spring-boot-starter-thymeleaf dependency

So I have used the below dependency instead,

        <dependency>
            <groupId>org.thymeleaf</groupId>
            <artifactId>thymeleaf</artifactId>
            <version>3.0.9.RELEASE</version>
        </dependency>

Spring Boot - Introduction, Spring Boot is a Framework from “The Spring Team” to ease the bootstrapping and development of new Spring Applications. It provides defaults for code and  I'm trying to make "hello world" application with gradle, spring boot and spring mvc with the simplest view resolver and html. I started from the thymeleaf spring boot example and I just wanted to remove thymeleaf to make a simpler mvc application using pure html and InternalResourceViewResolver. I have a single greeting.html I want to serve

If the above solutions don't work for you, like me,

I changed my Controller to a RestController. It fixed my issue.

This is, if you are using a Front End App like Angular to talk to your Back-end application.

Spring Boot Tutorial, Spring Boot provides a number of starter dependencies for different Spring modules. Some of the most commonly used ones are: spring-boot-  Spring Boot provides a very good support to building RESTful Web Services for enterprise applications. This chapter will explain in detail about building RESTful web services using Spring Boot. Note − For building a RESTful Web Services, we need to add the Spring Boot Starter Web dependency into the build configuration file.

A Comparison Between Spring and Spring Boot, Spring Boot provides selected groups of auto configured features and dependencies, which makes it faster to get started. 2. Tooling. 2.1. Let's learn how to create a SOAP Web Service with Spring Boot Starter Web Services. We will take a Contract First approach by definining an XSD and exposing a WSDL from it.

Spring Boot - Tutorial, spring-boot will scan for components in packages below com.nice.application , so if component classes which my project does not scan if i just give .controller. Today we will look into spring security role based access and authorization example. However before reading this post, please go through my previous post about “Spring 4 Security MVC Login Logout Example” to get some basic knowledge about Spring 4 Security.

Spring Boot Quick Start 5 - What Spring Boot gives us, Swagger UI empty and gives 403. Ask Question Asked 1 year, 10 months ago. I'm using spring boot security and I added this to my security configuration:

Comments
  • Nothing obvious is jumping out at me and Spring Boot has a sample the uses Thymeleaf with a layout (github.com/spring-projects/spring-boot/tree/master/…) so I don't think that's the problem. Perhaps looking at the sample could help spot a difference in your app's setup?
  • I encounter the same error and was able to fix it because of your answer, so thank you.
  • Thanks for posting this. What finally worked for me was to add the trailing slash to my property. spring.thymeleaf.prefix=classpath:/templates/
  • Unfortunately this didnt fix for me, have exact same problem. Eclipse works, with executable jar cant resolve template ... :-(
  • I got the same issue "org.thymeleaf.exceptions.TemplateInputException: Error resolving template "ui/applications", template might not exist or might not be accessible by any of the configured Template Resolvers" when deploying spring boot admin in weblogic. I can login successfully, but the request "/admin/ui/applications" to get the list of services got the issue. I have tried adding the configuration above "spring.thymeleaf.prefix: classpath:/templates" but didn't work. Any configuration to resolve this?
  • Welcome to SO, please describe your answer with more detail like bring some code sample, then users can understand your answer better