gradle - Thymeleaf views not found with springboot -


i trying follow tutorial adding thymeleaf springboot app can't seem work. tutorial: http://spr.com/part-2-adding-views-using-thymeleaf-and-jsp-if-you-want/

i able springboot work fine when started app using @restcontroller in logincontroller when changed @restcontroller @controller i'm getting error page saying:

there unexpected error (type=not found, status=404). no message available

i set breakpoint in controller , confirmed hitting index method in logincontroller. feel has how i've added thymeleaf since haven't done else application i've tried far results in same error page.

my build.gradle

buildscript { repositories {     maven { url "http://repo.spring.io/libs-snapshot" }     mavenlocal() } dependencies {     classpath("org.springframework.boot:spring-boot-gradle-plugin:1.4.0.release") } }  apply plugin: 'java' apply plugin: 'eclipse' apply plugin: 'idea' apply plugin: 'spring-boot'  jar { basename = 'gazefest' version =  '0.1.0' }  repositories { mavencentral() }  sourcecompatibility = 1.8 targetcompatibility = 1.8  dependencies { compile("org.springframework.boot:spring-boot-starter-web") compile("org.thymeleaf:thymeleaf-spring4:3.0.0.release") }  task wrapper(type: wrapper) { gradleversion = '3.0' } 

my application.java

package gazefest;

import org.springframework.boot.springapplication; import org.springframework.boot.autoconfigure.springbootapplication;  @springbootapplication public class application {  public static void main(string[] args) {     springapplication.run(application.class, args); }  } 

my logincontroller.java

package gazefest;  import org.springframework.stereotype.controller; import org.springframework.ui.model; import org.springframework.web.bind.annotation.requestmapping; import org.springframework.web.bind.annotation.restcontroller;  @controller public class logincontroller {  @requestmapping("/") public string index(model model) {     model.addattribute("message", "hello!");     return "index"; }  } 

my index.html

<!doctype html> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"> <head lang="en"> <meta charset="utf-8" /> <title>hello</title> </head> <body> <p th:text="${message}"></p> </body> </html> 

my file structure filestructure

thanks taking look!

i don't think should using thymeleaf-spring4 dependency, should using spring boot starter thymeleaf.

for maven:

<dependency>     <groupid>org.springframework.boot</groupid>     <artifactid>spring-boot-starter-thymeleaf</artifactid> </dependency> 

for gradle:

compile("org.springframework.boot:spring-boot-starter-thymeleaf") 

i suggest using spring initializr set project. allows select spring boot starter , add gradle/maven descriptor won't make mistakes picking dependency.


Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -