Spring Boot: Spring Boot 1.4.x & Thymeleaf 3.x configuration

David Marko  6 February 2017 07:54:40
Thymeleaf is quite popular template engine widely used among Spring Boot developers. And we use it as well. While working with Spring Boot 1.4.x you will find that spring-boot-starter-thymeleaf is based on older Thymeleaf 2.x version, while there is Thymeleaf 3.x available for some time.

But wait, there is an easy way how to get latest Thymeleaf for my Spring Boot 1.4.x application. There are 3 simple steps to do so.

1. Reference Thymeleaf in build.gradle file
(assuming we have Gradle based Spring Boot project)

compile("org.springframework.boot:spring-boot-starter-thymeleaf")
compile ("org.thymeleaf.extras:thymeleaf-extras-springsecurity4:3.0.0.RELEASE")
compile ("io.github.jpenren:thymeleaf-spring-data-dialect:3.1.1")

2. Specify Thymeleaf version in build.gradle file
Here is the place to say that we want version 3.x of Thymeleaf library

ext["thymeleaf.version"] = "3.0.2.RELEASE"
ext["thymeleaf-layout-dialect.version"] = "2.0.1"

3.  (Optional) Create @Configuration class with Thymeleaf configuration options. Spring Boot with detect this and create appropriate beans.

@Configuration
public class ThymeleafConfig extends WebMvcConfigurerAdapter implements ApplicationContextAware {

    @Autowired
    private MessageSource messageSource;

    @Value("${thymeleaf.templates.cache}")
    String thymeleafCache;

    private ApplicationContext applicationContext;

    public void setApplicationContext(ApplicationContext applicationContext) {
        this.applicationContext = applicationContext;
    }

    @Bean
    public ITemplateResolver templateResolver() {
        SpringResourceTemplateResolver templateResolver = new SpringResourceTemplateResolver();
        templateResolver.setApplicationContext(applicationContext);
        templateResolver.setPrefix("classpath:/templates/");
        templateResolver.setSuffix(".html");
        templateResolver.setTemplateMode("HTML");
        templateResolver.setCharacterEncoding("UTF-8");

        if (thymeleafCache.equals("true")){
            templateResolver.setCacheable(true);
        } else {
            templateResolver.setCacheable(false);
        }

        return templateResolver;
    }

    @Bean
    public SpringTemplateEngine templateEngine() {
        SpringTemplateEngine templateEngine = new SpringTemplateEngine();

        templateEngine.setEnableSpringELCompiler(true);
        templateEngine.setTemplateResolver(templateResolver());
        templateEngine.setMessageSource(messageSource);
        templateEngine.addDialect(new SpringDataDialect());

        return templateEngine;
    }

    @Bean
    public ViewResolver viewResolver() {
        ThymeleafViewResolver viewResolver = new ThymeleafViewResolver();
        viewResolver.setTemplateEngine(templateEngine());
        return viewResolver;
    }
}


You can find original blog post here.


Comments

1usps tracking  09.03.2017 13:55:55  Spring Boot: Spring Boot 1.4.x & Thymeleaf 3.x configuration

templateResolver() {

SpringResourceTemplateResolver templateResolver = new SpringResourceTemplateResolver();

templateResolver.setApplicatio

{ Link }

2varun  22.04.2017 11:16:12  Spring Boot: Spring Boot 1.4.x & Thymeleaf 3.x configuration

Vidmate is an app that lets you download videos and songs from the Youtube, Metacafe, Vimeo, Soundcloud and from other popular multimedia websites.

https://www.vidmateapk.co.in/

3varun  22.04.2017 11:16:31  Spring Boot: Spring Boot 1.4.x & Thymeleaf 3.x configuration

{ Link }

Vidmate is an app that lets you download videos and songs from the Youtube, Metacafe, Vimeo, Soundcloud and from other popular multimedia websites.

4james  28.04.2017 11:21:57  Thanks For Giving

{ Link }

5xfgfxcgfxcg  04.05.2017 9:57:12  Spring Boot: Spring Boot 1.4.x & Thymeleaf 3.x configuration

Welcome to USPS Tracking Track USPS Couriers & Parcels By Entering the USPS Tracking Number Track USPS Courier Online

{ Link }

6nikhil sharma  18.05.2017 9:43:37  Spring Boot: Spring Boot 1.4.x & Thymeleaf 3.x configuration

here is complete detail for usps service which is postal service of united state.here is complete detail for usps hold mail and tracking

7nikhil sharma  18.05.2017 9:44:23  Spring Boot: Spring Boot 1.4.x & Thymeleaf 3.x configuration

here is complete detail for usps service which is postal service of united state.here is complete detail for usps hold mail and tracking

{ Link }

8nikhil sharma  15.06.2017 15:08:56  Spring Boot: Spring Boot 1.4.x & Thymeleaf 3.x configuration

great stuff

9nikhil sharma  15.06.2017 15:09:14  Spring Boot: Spring Boot 1.4.x & Thymeleaf 3.x configuration

{ Link }

10nikhil sharma  15.06.2017 15:09:46  Spring Boot: Spring Boot 1.4.x & Thymeleaf 3.x configuration

{ Link }

{ Link }

11nikhil sharma  09.07.2017 15:09:28  Spring Boot: Spring Boot 1.4.x & Thymeleaf 3.x configuration

very great stuff.i really appreciate this.

https://www.uspstrackinginfo.com/usps-hold-mail-service/

https://www.uspstrackinginfo.com/usps-tracking-by-tracking-number/

12nikhil sharma  09.07.2017 15:10:29  Spring Boot: Spring Boot 1.4.x & Thymeleaf 3.x configuration

<a href="https://www.uspstrackinginfo.com/usps-hold-mail-service/">united state mail hold</a>

13tubemate 2.4.1 apk  21.08.2017 5:10:26  Spring Boot: Spring Boot 1.4.x & Thymeleaf 3.x configuration

great stuff

14Vidmate movies app  23.08.2017 7:11:14  Spring Boot: Spring Boot 1.4.x & Thymeleaf 3.x configuration

Vidmate for PC download with great features you can download any movie or video you like. Download videos with high speed, beautiful images. There are a variety of video format choices and resolutions for you to choose from.

Download:

{ Link }

15Vidmate movies app  23.08.2017 7:11:54  Spring Boot: Spring Boot 1.4.x & Thymeleaf 3.x configuration

Vidmate for PC download with great features you can download any movie or video you like. Download videos with high speed, beautiful images. There are a variety of video format choices and resolutions for you to choose from.

Download:

{ Link }

16mobdro for samsung smart tv  09.09.2017 8:37:36  Spring Boot: Spring Boot 1.4.x & Thymeleaf 3.x configuration

want to watch Mobdro For Smart TV and Mobdro for Samsung Smart TV LG And SONY tv

17mobdro for samsung smart tv  09.09.2017 8:38:20  Spring Boot: Spring Boot 1.4.x & Thymeleaf 3.x configuration

want to watch Mobdro For Smart TV and Mobdro for Samsung Smart TV LG And SONY tv

<a href="https://mobdropcwindows.co/mobdro-for-smart-tv/">mobdro for samsung smart tv</a>

18sunil bee  07.10.2017 14:54:29  Spring Boot: Spring Boot 1.4.x & Thymeleaf 3.x configuration

<a href="https://best-quotes.org/new-year/happy-new-year-wishes-quotes-greetings-messages/">Happy New Year Wishes </a>:

Just when we begin to enjoy Christmas, making snowmen and snow angels, the day of Christmas

<a href="https://best-quotes.org/new-year/new-year-shayari-2018-wishes-sms-messages-in-hindi/"> new year Shayari </a>

seems very fleeting and although it is celebrated as an entire festive season and not a day, in particular, the

arrival of a new dawn after Christmas leaves a bad taste in our mouths for the simple reason that Xmas is over.

“A new year is like a blank book, and the pen is in your hands.It is your chance to write a beautiful story for

yourself. Happy New Year”

Also Check:<a href="https://best-quotes.org/new-year/new-year-2018-images-pictures-wallpaper-images/ ">

New Year 2018 Images </a>

TOPlist