thymeleaf / thymeleaf-spring

Thymeleaf integration module for Spring
http://www.thymeleaf.org
Apache License 2.0
435 stars 157 forks source link

Class not found exception for spring boot template engine #301

Open Hazar6160 opened 2 years ago

Hazar6160 commented 2 years ago

Hello,

I've been upgraded spring boot version to 2.6.6, After that I am having a issue with template engine. It is throwing a java.lang.ClassNotFoundException: ognl.DefaultMemberAccess exception. Currently we are using a below dependencies for thymeleaf template engine. Anybody help me to resolve this issue?

            <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
    <dependency>
        <groupId>ognl</groupId>
        <artifactId>ognl</artifactId>
        <version>3.3.2</version>
    </dependency>
ultraq commented 2 years ago

Hi there, one thing that looks odd to me is that, when you're using Thymeleaf with Spring or Spring Boot, OGNL shouldn't be needed as a dependency any more. Spring Boot usually takes care of this configuration, so you might want to compare your project to some simple Spring Boot + Thymeleaf tutorials/projects out there.

For example, the Spring Boot website has a guide for setting up a Spring Boot project w/ Thymeleaf and includes an example application and GitHub repo. Looking at their pom.xml file in https://github.com/spring-guides/gs-serving-web-content/blob/main/complete/pom.xml, I can see only Spring Boot dependencies listed:

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

While that example repo is now using Spring Boot 2.7.1, I've found that the dependencies have remained largely the same across Spring Boot 2.x versions.

Hazar6160 commented 2 years ago

I've tried without ognl dependency, but still throwing a same issue.

Spring boot I am using 2.7.2.