2

I want to use simple-spring-memcached to cache data. so using this https://code.google.com/p/simple-spring-memcached/wiki/Getting_Started for my purpose. i add in my dispatcher-servlet.xml

  <aop:aspectj-autoproxy />
  <import resource="simplesm-context.xml" /> 
  <bean name="cacheManager" class="com.google.code.ssm.spring.SSMCacheManager">
    <property name="caches">
        <set>
            <bean class="com.google.code.ssm.spring.SSMCache">
                <constructor-arg name="cache" index="0" ref="defaultCache"/>
                <!-- 5 minutes -->
                <constructor-arg name="expiration" index="1" value="0"/>
                <!-- @CacheEvict(..., "allEntries" = true) doesn't work -->
                <constructor-arg name="allowClear" index="2" value="false"/>
            </bean>
        </set>
    </property>

</bean>
<bean name="defaultCache" class="com.google.code.ssm.CacheFactory">
    <property name="cacheName" value="defaultCache"/>
    <property name="cacheClientFactory">
        <bean name="cacheClientFactory"  class="com.google.code.ssm.providers.xmemcached.MemcacheClientFactoryImpl"/>
    </property>
    <property name="addressProvider">
        <bean class="com.google.code.ssm.config.DefaultAddressProvider">
            <property name="address" value="127.0.0.1:11211"/>
        </bean>
    </property>
    <property name="configuration">
        <bean class="com.google.code.ssm.providers.CacheConfiguration">
            <property name="consistentHashing" value="true"/>
        </bean>
    </property>
  </bean>

i also add simple-spring-memcached-3.5.0.jar and spymemcache.jar,spymemcache-provider.jar to lib folder. but when i run my project occur this exception:

 Cannot find class **[net.nelz.simplesm.config.MemcachedClientFactory]** for bean with name 'memcachedClientFactory' defined in ServletContext resource [/WEB-INF/simplesm-context.xml]; nested exception is java.lang.ClassNotFoundException: net.nelz.simplesm.config.MemcachedClientFactory
ragnor
  • 2,498
  • 1
  • 22
  • 25
Emil
  • 423
  • 1
  • 12
  • 34

2 Answers2

1

you must add lib for this class.

Hadi J
  • 16,989
  • 4
  • 36
  • 62
  • 1
    This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post - you can always comment on your own posts, and once you have sufficient [reputation](http://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](http://stackoverflow.com/help/privileges/comment). – Nilesh Nov 03 '14 at 12:00
  • because my reputation is low. – Hadi J Nov 03 '14 at 12:05
  • I think you can give comments to answer now. – Nilesh Nov 03 '14 at 12:19
0

It seams that you have also an old version of Simple Spring Memcached on your classpath. The class net.nelz.simplesm.config.MemcachedClientFactory is no longer available in 3.x. Check your classpath and remove all Simple Spring Memcached artifacts older than 3.5.0.

ragnor
  • 2,498
  • 1
  • 22
  • 25
  • i remove all simple-spring-memcached older than 3.5.0. but the exception occur yet. Caused by: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [net.nelz.simplesm.config.MemcachedClientFactory] for bean with name 'memcachedClientFactory' defined in ServletContext resource [/WEB-INF/simplesm-context.xml]; nested exception is java.lang.ClassNotFoundException: net.nelz.simplesm.config.MemcachedClientFactory – Emil Nov 04 '14 at 09:05
  • what is simplesm-context.xml and why use it? – Emil Nov 04 '14 at 09:06
  • `simplesm-context.xml` contains definition of beans used by Simple Spring Memcached. For some reason in your case it points to some old simplesm-context.xml (from version 1.x or 2.x). Check your classpath and make sure that the file is only available in `simple-spring-memcached-3.5.0.jar` – ragnor Nov 04 '14 at 09:24
  • i remove all ssm older than 3.5.0. my lib folder is: http://www.uploadimage.ro/img.php?image=2079_222_b35x.png – Emil Nov 04 '14 at 09:40
  • I assume that your application is distributed as a war. If so then unpack content of the war and use OS tool to find `simplesm-context.xml` file in the unpacked directory. Make sure that the tool will search also all archives (jar files). Maybe you have copied the file into your `WEB-INF` folder ? – ragnor Nov 04 '14 at 10:04
  • i unpack it. http://www.uploadimage.ro/img.php?image=7744_unpak_dxar.png but not fount com.google.code.ssm.spring.SSMCacheManager in it.why? – Emil Nov 04 '14 at 10:25
  • i add this jar file to lib xmemcached-provider-3.1.0.jar,xmemcached-2.0.0.jar, spring-cache-3.0.2.jar and not occur any excption. but i think caching not work. why? – Emil Nov 04 '14 at 11:03
  • The `SSMCacheManager` is in spring-cache-3.5.0.jar (it is SSM jar not Spring), [here](http://repo1.maven.org/maven2/com/google/code/simple-spring-memcached/spring-cache/3.5.0/spring-cache-3.5.0.jar) you can find it. Use maven to manage your dependencies. Use the latest SSM version 3.5.0 – ragnor Nov 04 '14 at 11:28