Java spring + Thymeleaf showing "Whitelabel Error Page"

Asked

Viewed 507 times

0

I am following a tutorial, however when starting my application it does not open the index page but an error page:

Mensagem de erro

Someone could help me?

Application start class:

package com.userFront;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;


@SpringBootApplication
public class UserFrontApplication {

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

}

POM:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.7.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.userFront</groupId>
    <artifactId>userFront</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>userFront</name>
    <description>User Frontend for online banking project</description>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>


        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

index page:

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head th:replace="common/header :: common-header"/>
<body>
<!-- Login Section -->
    <img class="img-responsive" src="/images/banner.png" alt="banner"/>
    <div class="container">
        <div class="row ">
            <div class="main-center ">
                <div class="bg-danger" th:if="${param.error}">
                    Invalid username and secret.
                </div>
                <div class="bg-danger" th:if="${param.logout}">
                    You have been logged out.
                </div>
                <form class="form-signin" th:action="@{/index}" method="post">
                    <h2 class="form-signin-heading">Please sign in</h2>
                    <div class="form-group">
                        <label for="username" class="sr-only">Username</label>
                        <input type="text" roleId="username" class="form-control" placeholder="Username" name="username"
                               id="username"
                               required="required" autofocus="autofocus"/>
                    </div>
                    <div class="form-group">
                        <label for="password" class="sr-only">Password</label>
                        <input type="password" roleId="inputPassword" class="form-control" placeholder="Password"
                               id="password"
                               name="password" required="required"/>
                    </div>
                    <div class="form-group">
                        <input type="checkbox" name="remember-me" id="remember-me"/> &nbsp; Remember me
                    </div>
                    <button class="btn btn-lg btn-primary btn-block" type="submit">Sign in</button>
                </form>

                <hr />

                <div class="form-group ">
                    <a type="submit" class="btn btn-info btn-lg btn-block login-button" th:href="@{/signup}">Sign up!</a>
                </div>
            </div>
        </div>
    </div>

<div th:replace="common/header :: body-bottom-scripts"/>

</body>
</html>

Controller:

package com.userFront.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class HomeController {

    @RequestMapping("/")
    public String home() {      
        return("redirect:/index");
    }

    @RequestMapping("/index")
    public String index() {     
        return("index");
    }


}

Project structure:

inserir a descrição da imagem aqui

stack trace:

 .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.1.7.RELEASE)

2019-09-03 10:13:10.564  INFO 4392 --- [           main] com.userFront.UserFrontApplication       : Starting UserFrontApplication on u6033451-TPD-A with PID 4392 (D:\Treinamento\javaEE\userFront\target\classes started by u6033451 in D:\Treinamento\javaEE\userFront)
2019-09-03 10:13:10.566  INFO 4392 --- [           main] com.userFront.UserFrontApplication       : No active profile set, falling back to default profiles: default
2019-09-03 10:13:11.138  INFO 4392 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2019-09-03 10:13:11.156  INFO 4392 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2019-09-03 10:13:11.156  INFO 4392 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.22]
2019-09-03 10:13:11.256  INFO 4392 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2019-09-03 10:13:11.257  INFO 4392 --- [           main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 670 ms
2019-09-03 10:13:11.384  INFO 4392 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2019-09-03 10:13:11.440  WARN 4392 --- [           main] ion$DefaultTemplateResolverConfiguration : Cannot find template location: classpath:/templates/ (please add some templates or check your Thymeleaf configuration)
2019-09-03 10:13:11.516  INFO 4392 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2019-09-03 10:13:11.518  INFO 4392 --- [           main] com.userFront.UserFrontApplication       : Started UserFrontApplication in 1.128 seconds (JVM running for 1.673)
2019-09-03 10:13:13.296  INFO 4392 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring DispatcherServlet 'dispatcherServlet'
2019-09-03 10:13:13.296  INFO 4392 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'dispatcherServlet'
2019-09-03 10:13:13.300  INFO 4392 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Completed initialization in 4 ms
2019-09-03 10:13:13.395 ERROR 4392 --- [nio-8080-exec-1] org.thymeleaf.TemplateEngine             : [THYMELEAF][http-nio-8080-exec-1] Exception processing template "index": Error resolving template [index], template might not exist or might not be accessible by any of the configured Template Resolvers

org.thymeleaf.exceptions.TemplateInputException: Error resolving template [index], template might not exist or might not be accessible by any of the configured Template Resolvers
    at org.thymeleaf.engine.TemplateManager.resolveTemplate(TemplateManager.java:869) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
    at org.thymeleaf.engine.TemplateManager.parseAndProcess(TemplateManager.java:607) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
    at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1098) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
    at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1072) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
    at org.thymeleaf.spring5.view.ThymeleafView.renderFragment(ThymeleafView.java:362) ~[thymeleaf-spring5-3.0.11.RELEASE.jar:3.0.11.RELEASE]
    at org.thymeleaf.spring5.view.ThymeleafView.render(ThymeleafView.java:189) ~[thymeleaf-spring5-3.0.11.RELEASE.jar:3.0.11.RELEASE]
  • 1

    He gave error 500. Must have presented some stack trace on the console. You can see it?

  • Following error: http://prntscr.com/p1801c

  • 1

    Ask the question so that the information is contained in it. And also avoid putting in images things that should be text.

  • Sorry, How big is the error I sent an image Please note: org.thymeleaf.exceptions.Templateinputexception: Error resolving template [index], template Might not exist or Might not be accessible by any of the configured Template Resolvers at org.thymeleaf.engine.TemplateManager.resolveTemplate(Templatemanager.java:869) ~[Thymeleaf-3.0.11.RELEASE. jar:3.0.11.RELEASE] at org.thymeleaf.engine.TemplateManager.parseAndProcess(Templatemanager.java:607) ~[Thymeleaf-3.0.11.RELEASE. jar:3.0.11.RELEASE]

  • You should [Dit] your question and add that relevant information. Taking advantage, you have read what the exception is about?

  • I will edit, Ja li yes, I’ve looked for the stack error, I’ve looked in this and other forums for the message that also appears in the browser, but I can’t solve the situation. Apparently my project is similar to the tutorial I’m following.

Show 2 more comments

1 answer

0


Solved:

The html folder was named "template" and should be "templates".

inserir a descrição da imagem aqui

Browser other questions tagged

You are not signed in. Login or sign up in order to post.