Announcement Announcement Module
No announcement yet.
New Spring Caching Not Working With AspectJ LTW Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • New Spring Caching Not Working With AspectJ LTW


    I would like to use LTW with AspectJ and Spring 3.1. I activated LTW via <context:load-time-weaver/>, put the right jars into their place, no exceptions are thrown but my methods annotated via @Cacheable are not adviced. No caching takes place. If I remove "mode=aspectj" from <cache:annotation-driven mode="aspectj"/> then Spring uses its auto-proxy mode and caching works fine.

    The problem is that I have methods which I execute via java reflection and those are therefore not AOP proxied by Spring. This would just be fine with LTW if it would work.

    Any help would be greatly appreciated.

  • #2

    I'm facing the same issue. Did you find a solution?

    Thank you.


    • #3
      Sorry for the delay - only now I've seen this thread. I've double checked our tests and everything runs fine - the aspectj aspect though was not part of the META-INF/aop.xml resource in the aspectj jar but that shouldn't really matter.
      Not sure what version are you using but can you please try the latest snapshot - we have improved the pointcut to be more efficient.
      If it still doesn't work for you take a look at the simple test configuration we have in aspects module and enable tracing to see what's going on. Most likely there is a weaving issue potentially caused by the LTW - what environment are you using?


      • #4
        Silviu, unfortunately I did not find a solution, it just would not work no matter what I tried. I eventually decided to change my design slightly so I can use Spring proxies instead of LTW. Please let me know if Costin's suggestion works as I might want to use LTW again some time in the future.


        • #5
          Hi Costin,

          thanks for getting back.

          I'm using spring framework 3.1.0 RC1. AS is JBOSS 6.1
          When I switched from proxy to aspectj for caching, I added the dependency org.springframework.spring-aspects.3.1.0-RC1
          It might be worth saying that I haven't got a META-INF/aop.xml in my project, as I was not using AOP before thinking to switch to aspectj for caching.
          I activated LTW with <context:load-time-weaver aspectj-weaving="on"/>

          If it is not too much too ask, could you please indicate the URL for the latest snapshot?

          Thank you.
          Last edited by silviu; Dec 11th, 2011, 02:41 AM.


          • #6
            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- 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- 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- 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 [] (http- Returning cached instance of singleton bean 'assetController'
            2011-12-12 16:38:57,654 DEBUG [org.springframework.web.servlet.DispatcherServlet] (http- Last-Modified value for [/myprj/asset/get/575d8dc0-01be-41e4-85ce-a654fab97fe8] is: -1
            2011-12-12 16:38:57,654 INFO  [] (http- Getting asset with id: 575d8dc0-01be-41e4-85ce-a654fab97fe8 - as binary data into the response


            • #7
              Hi Silviu
              You need to place the aop.xml into WEB-INF\classes\META-INF\aop.xml and it could look like:

                 <weaver options="-verbose -showWeaveInfo">
                    <include within="com.your.package..*"/>


              • #8
                Thanks, Daniel.

                Two questions, please :
                - my project is a web based project with 2 dependencies : my service jar and my dao jar. My @Cacheable methods are in dao classes.
                I have added 2 files :
                1) an aop.xml file to the META-INF (META-INF from the same level as WEB-INF)
                <!DOCTYPE aspectj PUBLIC"-//AspectJ//DTD//EN" "">
                   <weaver options="-verbose -showWeaveInfo">
                      <include within="com.mycompany.myproject.*"/>
                2) an application-config.xml to the WEB-INF
                <?xml version="1.0" encoding="UTF-8"?>
                <beans xmlns=""
                	<context:load-time-weaver aspectj-weaving="autodetect"/>
                - at my dao level (different jar) I added to my persistence-context.xml
                <!-- Use @Cacheable,.. annotations for managing cache -->
                	<cache:annotation-driven mode="aspectj"/>
                <!-- cache manager configuration -->
                	<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager" p:cache-manager-ref="ehcache"/>
                	<bean id="ehcache" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean" p:config-location="/WEB-INF/ehcache.xml"/>
                Does this look ok?

                - I noticed "-verbose -showWeaveInfo" options. Where can I see the output,please?

                Thank you.


                • #9
                  Hi Silviu
                  I am not familiar with JBOSS but can give you the info for Tomcat. Hopefully you can translate this into JBOSS settings.

                  You need to add to your tomcat\conf\context.xml file:
                  <Loader loaderClass="org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader" useSystemClassLoaderAsParent="false"/>
                  In Tomcat you would need to have the jar at tomcat\lib\org.springframework.instrument.tomcat-3.1.0.RC1.jar but this is not required for JBOSS. Nevertheless you might need to change a related setting. As I remember there was something about this somewhere in the Spring docs, it should not take you long to find the right spot.

                  The log output is written in Tomcat to the standard logging files.


                  • #10
                    Hi Daniel,

                    Thanks for the reply.

                    For JBOSS, I think there is nothing to be done....I read this part and proceed accordingly.

                    Recent versions of BEA WebLogic (version 10 and above), IBM WebSphere Application Server (version 7 and above), Oracle Containers for Java EE (OC4J and above), Resin (3.1 and above) and JBoss (5.x or above) provide a ClassLoader that is capable of local instrumentation. Spring's native LTW leverages such ClassLoaders to enable AspectJ weaving. You can enable LTW by simply activating context:load-time-weaver as described earlier. Specifically, you do not need to modify the launch script to add -javaagent: path/to/spring-instrument.jar.

                    Note that GlassFish instrumentation-capable ClassLoader is available only in its EAR environment. For GlassFish web applications, follow the Tomcat setup instructions as outlined above.

                    Note that on JBoss 6.x, the app server scanning needs to be disabled to prevent it from loading the classes before the application actually starts. A quick workaround is to add to your artifact a file named WEB-INF/jboss-scanning.xml with the following content:

                    <scanning xmlns="urn:jboss:scanning:1.0"/>


                    • #11
                      Hi to everyone!
                      Silviu, are you able to find a solution? I try with both xml configuration and annotation configuration, but i was not able to make it work with AspecJ.

                      Thank you.


                      • #12
                        No, unfortunatelly not...did not work for me.
                        I gave up on cache annotations as I was running out of time ... I ended up using ehcache objects "directly"

                        Thank you, Silviu


                        • #13
                          Same boat, Ive spent 3 days trying to get it to work.

                          Looks like the weaving falls over here, I think ive been looking at the problem too long and am missing something obvious.

                          DEBUG: org.springframework.context.annotation.ClassPathBe anDefinitionScanner - Identified candidate component class: URL [jar:file:/C:/Users/DEVELOPER/WORKSPACES/DIOMO_WS/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/DiomoFormsWeb/WEB-INF/lib/paypal-integration-service-1.0-SNAPSHOT.jar!/com/diomo/payments/paypal/ipn/web/IPNWebService.class]
                          [[email protected]] abort trouble in:
                          public abstract class extends java.lang.Object:


                          end public abstract class
                          -- (NullPointerException) null
                          at org.aspectj.weaver.UnresolvedType.forSignature(Unr