Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Spring Basics Creating Controllers and Views Using Thymeleaf to Serve HTML

Stefan Novak
Stefan Novak
6,791 Points

Whitelabel Error Page

Hey, after following this tutorial I no longer get a working webpage after restarting my server.

I followed the instructions and created a HTML file with all the closing tags. Removed the @RequestMapping annotation and I get a Whitelabel Error Page.

When I put that annotation back, I get a string called 'home' appear, so this got me thinking its something wrong with my java finding my html file? It's in the src/main/resources/templates folder.

Any advice?

I've meticulously checked my code, I don't see any spelling or syntax mistakes. Also I've updated my gradle file to use the most current versions of thymeleaf AND spring-boot, as I got a ton of errors when I removed that file.

" dependencies { compile group: 'org.thymeleaf', name: 'thymeleaf', version: '3.0.11.RELEASE' compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '2.1.4.RELEASE' } "

EDIT: Code

'''Java plugins { id 'java' id 'idea' id 'eclipse' id "org.springframework.boot" version "2.0.3.RELEASE" }

group 'com.teamtreehouse' version '1.0-SNAPSHOT'

sourceCompatibility = 1.8

repositories { mavenCentral() }

dependencies { compile group: 'org.thymeleaf', name: 'thymeleaf', version: '3.0.11.RELEASE' compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '2.1.4.RELEASE' } '''

'''Java package com.teamtreehouse.giflib;

import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.context.annotation.ComponentScan;

@EnableAutoConfiguration @ComponentScan public class AppConfig { public static void main(String[] args) { SpringApplication.run(AppConfig.class, args); } }

'''Java package com.teamtreehouse.giflib.controller;

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

@Controller public class GifController { @RequestMapping("/") public String listGifs() { return "home"; } } '''

Michael Hulet
Michael Hulet
47,912 Points

Can you post your code here, or better yet, a snapshot of your workspace? We can't really do anything to help without it

Stefan Novak
Stefan Novak
6,791 Points

I've added it Michael Hulet , I'm sorry it isn't formatted nicely I don't know how to do it

1 Answer

Stefan Novak
Stefan Novak
6,791 Points

Fixed after enquiring on Reddit. Make sure you use the spring-boot-starter-thymeleaf dependency, as found on MVN repository.

plugins { id 'java' id 'idea' id 'eclipse' id "org.springframework.boot" version "2.1.4.RELEASE" id "io.spring.dependency-management" version "1.0.7.RELEASE" }

group 'com.teamtreehouse' version '1.0-SNAPSHOT'

sourceCompatibility = 1.8

repositories { mavenCentral() }

dependencies { compile group: 'org.springframework.boot', name: 'spring-boot-starter-thymeleaf', version: '2.1.4.RELEASE' compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '2.1.4.RELEASE' }

works for me

Sergio Leon
Sergio Leon
12,594 Points

Thanks a lot, Stefan!

I wasn't able to make it work and couldn't find any solution and finally with your code I was able to finally make it!

Thanks man.

Stefan Novak
Stefan Novak
6,791 Points

no problem Sergio Leon , the biggest lesson I took from this course is don't rush through it. A lot of it is outdated, take your time, find the right dependencies, find the workarounds and make sure your program is working before starting the next tutorial :)