dinesh94 / simple-spring-memcached

Automatically exported from code.google.com/p/simple-spring-memcached
MIT License
0 stars 0 forks source link

The cache with name or alias 'default' is no defined #13

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.<!-- spring annotation package scan -->
    <context:component-scan base-package="com.zxhz"/>

    <aop:aspectj-autoproxy/>
    <mvc:annotation-driven/>

     <!-- memcached -->
    <import resource="classpath:simplesm-context.xml" />

    <bean name="defaultMemcachedClient" class="com.google.code.ssm.CacheFactory">
        <property name="cacheName" value="slfV5_Cache" />
        <property name="cacheClientFactory">
          <bean name="cacheClientFactory" class="com.google.code.ssm.providers.spymemcached.MemcacheClientFactoryImpl" />
        </property>
        <property name="addressProvider">
          <bean class="com.google.code.ssm.config.DefaultAddressProvider">
            <property name="address" value="192.168.1.62:11211" />
          </bean>
        </property>
        <property name="configuration">
          <bean class="com.google.code.ssm.providers.CacheConfiguration">
            <property name="consistentHashing" value="true" />
          </bean>
        </property>
      </bean>
2. Junit Test
3.[2012-12-13 19:32:05 0952 WARN ] [main] ssm.aop.ReadThroughAssignCacheAdvice 
- Caching on method execution(TestController.testssm()) and key [zt:zt] aborted 
due to an error.
com.google.code.ssm.aop.UndefinedCacheException: The cache with name or alias 
'default' is no defined
    at com.google.code.ssm.aop.CacheBase.getCache(CacheBase.java:108)
    at com.google.code.ssm.aop.SingleReadCacheAdvice.cache(SingleReadCacheAdvice.java:68)
    at com.google.code.ssm.aop.ReadThroughAssignCacheAdvice.cacheSingleAssign(ReadThroughAssignCacheAdvice.java:52)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:621)
    at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:610)
    at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:65)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:161)
    at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:90)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:621)
    at com.zxhz.web.TestController$$EnhancerByCGLIB$$5bc484b6.testssm(<generated>)
    at com.zxhz.slf.test.TestMemcachedClient.test(TestMemcachedClient.java:21)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
    at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
    at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:82)
    at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
    at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
    at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

spring3.0.5
SSM 3.10
Memcached for windows 1.2

Original issue reported on code.google.com by fengsezh...@gmail.com on 13 Dec 2012 at 11:45

GoogleCodeExporter commented 9 years ago
You're defining cache with custom cache's name: slfV5_Cache. 
You may:
1. remove <property name="cacheName" value="slfV5_Cache" /> so the cache will 
have default name

or

2. use annotation @CacheName("slfV5_Cache") on each method annotated with SSM 
annotations: @ReadThrough*, @Update*, @Invalidate*, in the case on 
com.zxhz.web.TestController.testssm

Original comment by ragno...@gmail.com on 13 Dec 2012 at 4:49

GoogleCodeExporter commented 9 years ago
thanks ! 
but today ,the project runing with tomcat . the cache is invalid!

xml :
<context:component-scan base-package="zt.ssmt"/>
<aop:aspectj-autoproxy/>
<mvc:annotation-driven/>
<import resource="classpath:simplesm-context.xml" />
    <bean name="defaultMemcachedClient" class="com.google.code.ssm.CacheFactory">
        <property name="cacheName" value="defaultCache" />
        <property name="cacheClientFactory">
          <bean name="cacheClientFactory" class="com.google.code.ssm.providers.spymemcached.MemcacheClientFactoryImpl" />
        </property>
        <property name="addressProvider">
          <bean class="com.google.code.ssm.config.DefaultAddressProvider">
            <property name="address" value="192.168.1.62:11211" />
          </bean>
        </property>
        <property name="configuration">
          <bean class="com.google.code.ssm.providers.CacheConfiguration">
            <property name="consistentHashing" value="true" />
          </bean>
        </property>
      </bean>

code:
    @RequestMapping("/")
    public void con(){
        for (int i = 0; i < 5; i++) {
            log.info(ssm());
        }
    }

    @ReadThroughAssignCache(assignedKey="zhang",expiration=3600,namespace="zhang")
    public String ssm(){
        log.info("run one");
        return "run any";
    }

console:
.............
2012-12-14 10:57:29.237 INFO net.spy.memcached.MemcachedConnection:  Added {QA 
sa=/192.168.1.62:11211, #Rops=0, #Wops=0, #iq=0, topRop=null, topWop=null, 
toWrite=0, interested=0} to connect queue
2012-12-14 10:57:29.253 INFO net.spy.memcached.MemcachedConnection:  Connection 
state changed for sun.nio.ch.SelectionKeyImpl@6f156508
...............
[2012-12-14 10:57:37 0333 INFO ] [http-80-2] zt.ssmt.SsmtComtroller - run one
[2012-12-14 10:57:37 0333 INFO ] [http-80-2] zt.ssmt.SsmtComtroller - run any
[2012-12-14 10:57:37 0333 INFO ] [http-80-2] zt.ssmt.SsmtComtroller - run one
[2012-12-14 10:57:37 0333 INFO ] [http-80-2] zt.ssmt.SsmtComtroller - run any
[2012-12-14 10:57:37 0333 INFO ] [http-80-2] zt.ssmt.SsmtComtroller - run one
[2012-12-14 10:57:37 0333 INFO ] [http-80-2] zt.ssmt.SsmtComtroller - run any
[2012-12-14 10:57:37 0333 INFO ] [http-80-2] zt.ssmt.SsmtComtroller - run one
[2012-12-14 10:57:37 0333 INFO ] [http-80-2] zt.ssmt.SsmtComtroller - run any
[2012-12-14 10:57:37 0333 INFO ] [http-80-2] zt.ssmt.SsmtComtroller - run one
[2012-12-14 10:57:37 0333 INFO ] [http-80-2] zt.ssmt.SsmtComtroller - run any

i don't know where is error!

Original comment by fengsezh...@gmail.com on 14 Dec 2012 at 2:59

GoogleCodeExporter commented 9 years ago
The error is self invocation, invoking ssm() method in con() method using 
'this' reference (the same object). Spring doesn't intercept self invocations, 
such invocation omits proxy so the SSM is not invoked. Move ssm() method to 
another bean: MyCache and inject the bean to bean with con() method. 

Original comment by ragno...@gmail.com on 14 Dec 2012 at 6:34

GoogleCodeExporter commented 9 years ago
so! 
This method has four parameters!
method :
public Object getSpec(int merId,String code,int type,httpservletrequest 
request){
       //TODO 
}

I want to use the three parameter as cache key

What should I do?

 Thank you very much! thanks a lot!

Original comment by fengsezh...@gmail.com on 14 Dec 2012 at 7:02

GoogleCodeExporter commented 9 years ago
To create cache key using many parameters use @ParameterValueKeyProvider 
annotation:

@ReadThroughSingleCache(namespace = "spec", expiration = 3600)
public Object getSpec(@ParameterValueKeyProvider(order = 0) int merId, 
@ParameterValueKeyProvider(order = 1) String code, 
@ParameterValueKeyProvider(order = 2) int type,httpservletrequest request){
       //TODO 
}

Original comment by ragno...@gmail.com on 14 Dec 2012 at 7:14

GoogleCodeExporter commented 9 years ago
Thank you very much indeed.
It’s very kind of you.

Original comment by fengsezh...@gmail.com on 14 Dec 2012 at 7:23

GoogleCodeExporter commented 9 years ago
No problem :).
Next time please use SSM's mailing group: 
http://groups.google.com/group/simple-spring-memecached

Best regards,
Ragnor

Original comment by ragno...@gmail.com on 14 Dec 2012 at 7:31