Thymeleaf doesn't see page templates

68 views Asked by At

When I run applications from IDEA everything works correctly. But after I packed the .jar archive, when I run the .jar file, Thymemleaf does not find the templates.

I use: Java 17 + Maven 3.2.0 + Thymeleaf 3.1.1.RELEASE

pon.xml

<parent>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-parent</artifactId>
   <version>3.2.0</version>
   <relativePath/>
</parent>

<properties>
   <java.version>17</java.version>
</properties>

<dependencies>
     <dependency>
        <groupId>org.thymeleaf.extras</groupId>
            <artifactId>thymeleaf-extras-springsecurity6</artifactId>
            <version>3.1.1.RELEASE</version>
        <dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-validation</artifactId>
            <!--            <version>3.1.5</version>-->
        </dependency>

        <!--Security-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-test</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
        </dependency>

        <!-- swagger -->
        <dependency>
            <groupId>org.springdoc</groupId>
            <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
            <version>2.2.0</version>
        </dependency>

        <dependency>
            <groupId>org.springdoc</groupId>
            <artifactId>springdoc-openapi-starter-webmvc-api</artifactId>
            <version>2.2.0</version>
        </dependency>

        <!-- 100% -->
        <dependency>
            <groupId>org.thymeleaf.extras</groupId>
            <artifactId>thymeleaf-extras-springsecurity6</artifactId>
            <version>3.1.1.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.33</version>
            <scope>runtime</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.modelmapper</groupId>
            <artifactId>modelmapper</artifactId>
            <version>3.1.1</version>
        </dependency>

        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter</artifactId>
            <version>5.10.1</version>
            <scope>test</scope>
    </dependency>
</dependency>

</dependencies>

application.properties

#ThymeLeaf Edit
spring.thymeleaf.cache=false
spring.thymeleaf.prefix=classpath:/templates/
spring.web.resources.static-locations=classpath:/static/
spring.web.resources.cache.period=0

folder hierarchy

src
└── main
    ├── java
    │   └── com
    │       └── example
    │           └── Application.java
    └── resources
        ├── static
        │   ├── assets
        │   │   └── css
        │   │       └── style.css
        │   └── images
        │       └── logo
        │           └── logo-dark.png
        └── templates
            ├── blocks
            │   ├── footer.html
            │   ├── header.html
            │   └── sidebar.html
            ├── admin
            │   └── products
            │       └── add.html
            └── index.html

I collected everything into a .jar archive using Maven. I climbed inside the archive and there all the files were in their places, according to the hierarchy. But Thymeleaf does not see these patterns

I caught it in the logs

log

code

Managed to solve the problem. R emoved / after {

<div th:insert="~{blocks/sidebar :: sidebar}"></div>
0

There are 0 answers