[main] WARN GenericApplicationContext:591 – Exception encountered during context initialization – cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘sessionFactory’ defined in class path resource : Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: net/bytebuddy/TypeCache

On upgrading Hibernate from version 3 to version 5, I got the above error.

Turned out that we were also using Mockito and it also has a dependency on byte buddy. So there was conflict of versions of byet buddy.

So here is fix:

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>2.2.28</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
</exclusion>
</exclusions>
</dependency>

exclude the byte-buddy jar from mockito.

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.