casid / jte

Secure and speedy templates for Java and Kotlin.
https://jte.gg
Apache License 2.0
748 stars 56 forks source link

Error 404 not rendering JTE Spring Boot 3 #276

Closed ccortes66 closed 11 months ago

ccortes66 commented 11 months ago

Hello, how are you? Following the documentation and the examples presented on GitHub, the precompiled templates are not rendering. When generating the JAR, it looks for the path and throws a 404 Not Found error.


<build>
        <plugins>

            <plugin>
                <groupId>org.hibernate.orm.tooling</groupId>
                <artifactId>hibernate-enhance-maven-plugin</artifactId>
                <version>${hibernate.version}</version>
                <executions>
                    <execution>
                        <id>enhance</id>
                        <goals>
                            <goal>enhance</goal>
                        </goals>
                        <configuration>
                            <enableLazyInitialization>true</enableLazyInitialization>
                            <enableDirtyTracking>true</enableDirtyTracking>
                            <enableAssociationManagement>true</enableAssociationManagement>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
            </plugin>

            <plugin>
                <groupId>gg.jte</groupId>
                <artifactId>jte-maven-plugin</artifactId>
                <version>3.1.0</version>
                <configuration>
                    <sourceDirectory>src/main/resources/templates</sourceDirectory> <!-- This is the directory where your .jte files are located. -->
                    <targetDirectory>jte-classes</targetDirectory> <!-- This is the directory where compiled templates are located. -->
                    <contentType>Html</contentType>
                </configuration>
                <executions>
                    <execution>
                        <phase>process-classes</phase>
                        <goals>
                            <goal>precompile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <artifactId>maven-resources-plugin</artifactId>
                <version>3.3.1</version>
                <executions>
                    <execution>
                        <id>copy-resources</id>
                        <phase>process-classes</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.outputDirectory}</outputDirectory>
                            <resources>
                                <resource>
                                    <directory>${basedir}/target/generated-sources/jte</directory>
                                    <includes>
                                        <include>**/*.class</include>
                                    </includes>
                                    <filtering>false</filtering>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

        </plugins>
    </build>
casid commented 11 months ago

Hi, can you share a sample project, that demonstrates the problem?

ccortes66 commented 11 months ago

The error occurs when I generate the JAR in Maven. It compiles successfully, but when it's compiled and put into production, the pages generated in JTE don't appear. Instead, I get a 404 error. This is without considering Spring Security. I tried recompiling the project after removing all Spring Security-related parts, but the error persisted. I have shared the project on GitHub. I was using Spring MVC with JTE.

https://github.com/ccortes66/G5_alura_one_hotel_alura_spring_mvc

casid commented 11 months ago

I tried compiling and starting your application, but it failed with missing data source in flyway migration. I'm not a spring boot user, so I stopped debugging there :-)

Are the precompiled jte-classes located next to your application jar?

What exception was logged by your application?

ccortes66 commented 11 months ago

hi That GitHub repository uses Flyway for performing migrations in the MariaDB database. In this branch, the project has been modified by removing certain parts. To view the project, it uses SQLite as the database

https://github.com/ccortes66/G5_alura_one_hotel_alura_spring_mvc/tree/sqlite_version

casid commented 11 months ago

Sorry, that is not helpful. I won't try to debug your application. I just ran it once more and got an infinite redirect, when visiting localhost:8080 Firefox has detected that the server is redirecting the request for this address in a way that will never complete.

Please provide a stacktrace of the exception you are experiencing.

ccortes66 commented 11 months ago

Following thread #280 was very helpful. I created a new production profile in Spring Boot with the following characteristics:

profile application-prod.yml

gg:
  jte:
      developmentMode: false
      usePrecompiledTemplates: true

pom.xml


<build>
        <plugins>

            <plugin>
                <groupId>org.hibernate.orm.tooling</groupId>
                <artifactId>hibernate-enhance-maven-plugin</artifactId>
                <version>${hibernate.version}</version>
                <executions>
                    <execution>
                        <id>enhance</id>
                        <goals>
                            <goal>enhance</goal>
                        </goals>
                        <configuration>
                            <enableLazyInitialization>true</enableLazyInitialization>
                            <enableDirtyTracking>true</enableDirtyTracking>
                            <enableAssociationManagement>true</enableAssociationManagement>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
            </plugin>

            <plugin>
                <groupId>gg.jte</groupId>
                <artifactId>jte-maven-plugin</artifactId>
                <version>3.1.0</version>
                <configuration>
                    <sourceDirectory>src/main/jte</sourceDirectory> 
                    <contentType>Html</contentType>
                </configuration>
                <executions>
                    <execution>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

        </plugins>
    </build>

Muchas Gracias,me salvo de usar thymeleaf