Reputation: 279
I'm using cache abstraction mechanism from Spring 3.0 RC1 : I've set up bytecode (based on AspectJ) weawing so that cache mechanism can be applied to methods called from within the class itself. It is worth saying that first I was using proxy-based approach : everything was working fine (for methods are invoked from another object.)
As soon as I switch to AspectJ (I activated LTW via , added the right jars into their place - everything is working fine, no exceptions are thrown),no caching takes place
Any suggestion? Thank you.
==== later edit ========
I set up the logs to DEBUG for org.springframework.
If using proxy mode, I can clearly see the message Adding cacheable method 'getLargeAssetContent'.... where getLargeAssetContent is my "cacheable" method...(please see bellow)
If using aspectj mode, I don't see this message....every requests goes to the DAO layer...where as, in situation where cache works, requests stop at service layer.
What I am doing wrong? Do I need an aop.xml? I was not using AOP...., so I don't have yet an aop.xml.
Thank you for your help.
*> *2011-12-12 16:38:55,998 DEBUG [org.springframework.cache.annotation.AnnotationCacheOperationSource]
(http-127.0.0.1-8080-6) Adding cacheable method 'getLargeAssetContent' with attribute: [CacheOperation[public com.mycompany.myprj.model.AssetContent com.mycompany.myprj.dao.jcr.AssetDAOImpl.getLargeAssetContent(java.lang.String) throws com.mycompany.myprj.dao.MyPrjPersistenceException] caches=[assets] | condition='' | key='#nodeId'] 2011-12-12 16:38:56,013 INFO [com.mycompany.myprj.dao.jcr.AssetDAOImpl] (http-127.0.0.1-8080-6) Getting the content (getLargeAssetContent) of asset from node with id=575d8dc0-01be-41e4-85ce-a654fab97fe8 2011-12-12 16:38:56,092 INFO [com.mycompany.myprj.dao.jcr.AssetDAOImpl] (http-127.0.0.1-8080-6) Returning the content of asset from node with id=575d8dc0-01be-41e4-85ce-a654fab97fe8**
*
//the content is cached by now 2011-12-12 16:38:57,654 DEBUG [org.springframework.beans.factory.support.DefaultListableBeanFactory] (http-127.0.0.1-8080-6) Returning cached instance of singleton bean 'assetController' 2011-12-12 16:38:57,654 DEBUG [org.springframework.web.servlet.DispatcherServlet] (http-127.0.0.1-8080-6) Last-Modified value for [/myprj/asset/get/575d8dc0-01be-41e4-85ce-a654fab97fe8] is: -1 2011-12-12 16:38:57,654 INFO [com.mycompany.myprj.services.AssetService] (http-127.0.0.1-8080-6) Getting asset with id: 57
*
Upvotes: 5
Views: 2709
Reputation: 2311
I tried it with a sample project and needed to do the following to switch from regular proxy to aspectj LTW
<cache:annotation-driven mode="aspectj"/>
<context:load-time-weaver aspectj-weaving="on"/>
(Default is autodetect which will silently fail if META-INF/aop.xml is not found)javaagent
switch the VM and point it to the spring-instrument jar if you are using it standalone. If you are in a container you can either use the javaagent or have it configured to a specific classloader as mentioned in the reference.Upvotes: 0
Reputation: 340708
Make sure AspectJ mode is enabled (see 28.3.3 Enable caching annotations):
<cache:annotation-driven mode="aspectj"/>
By default caching abstraction uses proxy
mode, despite having LTW enabled (should switch automatically to aspectj
IMHO, but it doesn't).
If this does not help examine stack trace when calling cached method from outside and from inside - what are the differences?
Upvotes: 1