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

Florian Tönjes
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Florian Tönjes
Full Stack JavaScript Techdegree Graduate 50,856 Points

How does the application know it should use Thymeleaf?

So after finishing this course I am wondering how the application knows that it should use Thymeleaf. Flying over the code the only reference to Thymeleaf that I can find is as a dependency in the 'build.gradle' file.

I would have expected something like this in 'AppConfig.java'

import org.thymeleaf.TemplateEngine;

SpringApplication.run(AppConfig.class, TemplateEngine.getTemplateEngine(), args);

which tells Spring to use Thymeleaf, but apparently this is not happening.

Is it that this code in the 'build.gradle' file

dependencies {
    compile 'org.springframework.boot:spring-boot-starter-thymeleaf'
}

not only fetches Thymeleaf, but also directly integrates it into Spring?

Kind Regards, Florian

1 Answer

Chris Ramacciotti
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Chris Ramacciotti
Treehouse Guest Teacher

Great question, Florian. This is Spring Boot at work. There are a number of items for which Spring Boot provides auto-configuration, and template engines are one of them. What happens is that Spring Boot (with SpringApplication.run) scans the classpath, and upon seeing Thymeleaf, the auto-configuration is executed. Check out this page for supported template engines.

Spring Boot is quite powerful in this way. Expect to see more courses and workshops on Treehouse that showcase its "magic"!