thymeleaf-spring icon indicating copy to clipboard operation
thymeleaf-spring copied to clipboard

Class not found exception for spring boot template engine

Open Hazar6160 opened this issue 3 years ago • 2 comments

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>

Hazar6160 avatar Jul 26 '22 05:07 Hazar6160

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.

ultraq avatar Jul 26 '22 08:07 ultraq

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

Spring boot I am using 2.7.2.

Hazar6160 avatar Jul 26 '22 08:07 Hazar6160