[JAVA] Use thymeleaf3 with parent without specifying spring-boot-starter-parent in Spring Boot

As described in the Spring documentation, when using thymeleaf 3 with Spring Boot, if parent is spring-boot-starter-parent, you can use it by specifying it in properties like this.

<properties>
    <thymeleaf.version>3.0.2.RELEASE</thymeleaf.version>
    <thymeleaf-layout-dialect.version>2.1.1</thymeleaf-layout-dialect.version>
</properties>

However, spring-boot-starter-parent cannot be specified as parent when the company has decided the pom to be specified as parent. In that case, the setting to use thymeleaf 3 was complicated, so make a note of it.

Also in here Although it is written, if it is not specified as parent, write spring-boot-dependency in <dependencyManagement>

<dependencyManagement>
     <dependencies>
        <dependency>
            <!-- Import dependency management from Spring Boot -->
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-dependencies</artifactId>
            <version>1.5.6.RELEASE</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

What it does is specify the version of dependencies required by Spring Boot. The one that enters by default is written in here or in the pom of the head family. If you continue to use it, thymeleaf 2.1.5 will be installed. Since I want to use 3, write the version of the module you want to change before spring-boot-dependencies of <dependencyManagemet> and overwrite it.

<properties>
    <spring-boot.version>1.5.6.RELEASE</spring-boot.version>
    <thymeleaf.version>3.0.7.RELEASE</thymeleaf.version>
    <thymeleaf-spring4.version>3.0.7.RELEASE</thymeleaf-spring4.version>
    <thymeleaf-layout-dialect.version>2.2.2</thymeleaf-layout-dialect.version>
  </properties>
<dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>org.thymeleaf</groupId>
        <artifactId>thymeleaf</artifactId>
        <version>${thymeleaf.version}</version>
      </dependency>
      <dependency>
        <groupId>nz.net.ultraq.thymeleaf</groupId>
        <artifactId>thymeleaf-layout-dialect</artifactId>
        <version>${thymeleaf-layout-dialect.version}</version>
      </dependency>
      <dependency>
        <groupId>org.thymeleaf</groupId>
        <artifactId>thymeleaf-spring4</artifactId>
        <version>${thymeleaf-spring4.version}</version>
      </dependency>
      <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-dependencies</artifactId>
        <version>${spring-boot.version}</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>

It is like this. If you just write in <dependencyManagement>, the essential module will not be installed, so I will write the module to be installed in <dependencies>.

<dependencies>
    <dependency>
   <dependency>
      <groupId>org.thymeleaf</groupId>
      <artifactId>thymeleaf-spring4</artifactId>
    </dependency>
    <dependency>
      <groupId>nz.net.ultraq.thymeleaf</groupId>
      <artifactId>thymeleaf-layout-dialect</artifactId>
    </dependency>
  </dependencies>

Like this! If spring-boot-starter-thymeleaf is written in pom, delete it.

Trigger

At first I wanted to use LocalDateTime with thymeleaf, so I put thymeleaf-extras-java8time, but When from is null in #temporals.format (from,'yyyyMMdd'), ʻIllegalArgumentException: Cannot apply format on nullappears in the 2nd system and it is difficult to use 3.0. I found that it was solved in 1. [This](https://github.com/thymeleaf/thymeleaf-extras-java8time/issues/14) However, the 3 system of thymeleaf-extras-java8time must be thymeleaf 3, so for the time being, if I thought that I should set the version of thymeleaf to 3 in properties, I got an error likeClassNotFoundException IExpressionObjectDialect` and I will investigate It seems that the version was still thymeleaf 2 when I just specified it in properties.

Recommended Posts

Use thymeleaf3 with parent without specifying spring-boot-starter-parent in Spring Boot
Use Spring JDBC with Spring Boot
Use Basic Authentication with Spring Boot
Beginning with Spring Boot 0. Use Spring CLI
Thymeleaf usage notes in Spring Boot
Loosen Thymeleaf syntax checking in Spring Boot
Use DynamoDB query method in Spring Boot
Implement CRUD with Spring Boot + Thymeleaf + MySQL
Implement paging function with Spring Boot + Thymeleaf
Use cache with EhCashe 2.x with Spring Boot
Run WEB application with Spring Boot + Thymeleaf
Test controller with Mock MVC in Spring Boot
Asynchronous processing with regular execution in Spring Boot
Use Thymeleaf text template mode from Spring Boot
How to use MyBatis2 (iBatis) with Spring Boot 1.4 (Spring 4)
Use Servlet filter in Spring Boot [Spring Boot 1.x, 2.x compatible]
Create CRUD apps with Spring Boot 2 + Thymeleaf + MyBatis
Create your own Utility with Thymeleaf with Spring Boot
[JAVA] [Spring] [MyBatis] Use IN () with SQL Builder
Organize the differences in behavior of @NotBlank, @NotEmpty, @NotNull with Spring Boot + Thymeleaf
Use Interceptor in Spring
Download with Spring Boot
SSO with GitHub OAuth in Spring Boot 1.5.x environment
How to use CommandLineRunner in Spring Batch of Spring Boot
Until you start development with Spring Boot in eclipse 1
Until you start development with Spring Boot in eclipse 2
Database environment construction with Docker in Spring boot (IntellJ)
File upload with Spring Boot (do not use Multipart File)
Set context-param in Spring Boot
Generate barcode with Spring Boot
Hello World with Spring Boot
Implement GraphQL with Spring Boot
Handle Java 8 date and time API with Thymeleaf with Spring Boot
Hello World with Spring Boot!
Spring Boot 2 multi-project in Gradle
How to use the same Mapper class in multiple data sources with Spring Boot + MyBatis
Run LIFF with Spring Boot
SNS login with Spring Boot
[Java] Thymeleaf Basic (Spring Boot)
File upload with Spring Boot
Spring Boot starting with copy
Until INSERT and SELECT to Postgres with Spring boot and thymeleaf
How to call and use API in Java (Spring Boot)
Spring Boot starting with Docker
Spring Boot + Springfox springfox-boot-starter 3.0.0 Use
Hello World with Spring Boot
Set cookies with Spring Boot
Major changes in Spring Boot 1.5
Add module with Spring Boot
Getting Started with Spring Boot
NoHttpResponseException in Spring Boot + WireMock
Create microservices with Spring Boot
Send email with spring boot
Use @ControllerAdvice, @ExceptionHandler, HandlerExceptionResolver in Spring Boot to catch exceptions
How to control transactions in Spring Boot without using @Transactional
Easily develop web applications with STS and Spring Boot. In 10 minutes.
[Linux: Ruby] Use the driver with selenium without specifying the browser driver path
See the relative redirect behavior with the server.tomcat.use-relative-redirects setting in Spring Boot
Compare Hello, world! In Spring Boot with Java, Kotlin and Groovy
How to use Lombok in Spring
Spring Boot Hello World in Eclipse