1

I am using the spring 3.2 version along with net.sf cache, but while doing mvn build I am getting NoClassDefFoundError for EhCacheFactoryBean, but I checked a similar class available in my classpath below is my stack trace

      Failed to load ApplicationContext Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 
distributorStartupAndConfigurationListener': 
Injection of autowired dependencies failed; 
nested exception is org.springframework.beans.factory.BeanCreationException: Could not 
autowire field: protected DistributorConfiguration 
DistributorStartupAndConfigurationListener.distributorConfiguration;nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'filePathCache' defined in class path resource [META-INF/spring/cms-client-context.xml]:Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: Could not initialize class org.springframework.cache.ehcache.EhCacheFactoryBean Caused by:   org.springframework.beans.factory.BeanCreationException: Could not autowire field: protected DistributorConfiguration .DistributorStartupAndConfigurationListener.distributorConfiguration;  nested exception is org.springframework.beans.factory.BeanCreationException: Error
         creating 
                 bean with name 'filePathCache' defined in class path resource [META-INF/spring/cms-client- 
                 context.xml]: Instantiation of bean failed; nested exception is 
                 java.lang.NoClassDefFoundError: Could not initialize class 
                 org.springframework.cache.ehcache.EhCacheFactoryBean Caused by: 
                 org.springframework.beans.factory.BeanCreationException: Error creating bean with name 
                 'filePathCache' defined in class path resource [META-INF/spring/cms-client-context.xml]: 
                 Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: Could not 
                initialize class org.springframework.cache.ehcache.EhCacheFactoryBean Caused by: 
           **java.lang.NoClassDefFoundError: Could not initialize class 
     org.springframework.cache.ehcache.EhCacheFactoryBean**

below is my pom.xml

    <dependency> 
     <groupId>org.springframework</groupId>
     <artifactId>spring-context-support</artifactId>
     <version>5.3.21</version>
    </dependency> 

    <dependency> 
      <groupId>net.sf.ehcache</groupId>
      <artifactId>ehcache</artifactId>
      <version>2.10.9.2</version> 
    </dependency>
   
    <repository> 
     <id>sourceforge</id>
     <url>http://oss.sonatype.org/content/groups/sourceforge/</url> 
      <releases> 
        <enabled>true</enabled>
      </releases>
     <snapshots>
     <enabled>true</enabled>
     </snapshots> 
    </repository>
    
     And in application-context.xml : 
    
    <bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager"> 
    <property name="cacheManagerRef"> 
      <ref local="ehcache"/> 
    </property> 
    </bean>
    
    <bean id="ehcache" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
     <property name="configLocation"> 
       <value>classpath:META-INF/spring/ehcache.xml</value> 
      </property> 
    </bean>
    
    <bean id="filePathCache" class="org.springframework.cache.ehcache.EhCacheFactoryBean"> 
    <property name="cacheManager"> <ref local="cacheManager" /> </property> 
    <property name="cacheName"> <value>getFilePathCache</value> </property> 
    </bean>
    

Not sure what I am doing wrong here, Could you please help me resolve this issue?

LowCool
  • 1,187
  • 5
  • 25
  • 51

0 Answers0