javaspringspring-bootguava

java.lang.ClassNotFoundException: org.springframework.cache.guava.GuavaCache


Context -

I have a spring boot app and I updated the spring-boot-starter-parent version from 1.5.12.RELEASE to 2.4.0

I had this dependency in my pom -

<dependency>
    <groupId>com.google.guava</groupId>
    <artifactId>guava</artifactId>
    <version>30.1-android</version>
</dependency>

Now when I am running my app, I am getting this error -

    org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'cachesEndpoint' defined in class path resource ...

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'guavaCacheManager' defined in class path resource...

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.cache.CacheManager]: Factory method 'guavaCacheManager' threw exception; nested exception is java.lang.NoClassDefFoundError: org/springframework/cache/guava/GuavaCache ...

Caused by: java.lang.NoClassDefFoundError: org/springframework/cache/guava/GuavaCache
    at biz.kaar.common.services.cache.TempGuavaCacheConfig.guavaCacheManager(TempGuavaCacheConfig.java:32)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:567)
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
    ... 43 common frames omitted
Caused by: java.lang.ClassNotFoundException: org.springframework.cache.guava.GuavaCache
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:636)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:182)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:519)
    ... 49 common frames omitted

Solution

  • I resolved this by completely removing guava dependency and its references from my project.

    If you still need to use caching then try using Caffeine.