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

  • New Spring Caching Not Working With AspectJ LTW

    Hi

    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
    Hi

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

    Thank you.

    Comment


    • #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?

      Comment


      • #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.

        Comment


        • #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, 01:41 AM.

          Comment


          • #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.


            Code:
            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: 575d8dc0-01be-41e4-85ce-a654fab97fe8 - as binary data into the response

            Comment


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

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

              Comment


              • #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)
                Code:
                <!DOCTYPE aspectj PUBLIC"-//AspectJ//DTD//EN" "http://www.eclipse.org/aspectj/dtd/aspectj.dtd">
                <aspectj>
                   <weaver options="-verbose -showWeaveInfo">
                      <include within="com.mycompany.myproject.*"/>
                   </weaver>
                </aspectj>
                2) an application-config.xml to the WEB-INF
                Code:
                <?xml version="1.0" encoding="UTF-8"?>
                <beans xmlns="http://www.springframework.org/schema/beans"
                	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                	xmlns:context="http://www.springframework.org/schema/context"
                	xmlns:p="http://www.springframework.org/schema/p"
                	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
                		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">
                	<context:load-time-weaver aspectj-weaving="autodetect"/>
                </beans>
                - at my dao level (different jar) I added to my persistence-context.xml
                Code:
                <!-- 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.

                Comment


                • #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:
                  Code:
                  <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.

                  Comment


                  • #10
                    Hi Daniel,

                    Thanks for the reply.

                    For JBOSS, I think there is nothing to be done....I read this part and proceed accordingly.
                    http://static.springsource.org/sprin...-aj-ltw-spring

                    Recent versions of BEA WebLogic (version 10 and above), IBM WebSphere Application Server (version 7 and above), Oracle Containers for Java EE (OC4J 10.1.3.1 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"/>

                    Comment


                    • #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.

                      Comment


                      • #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

                        Comment


                        • #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]
                          [TomcatInstrumentableClassLoader@755c62bc] abort trouble in:
                          public abstract class org.codehaus.jackson.map.SerializerProvider extends java.lang.Object:


                          ....

                          end public abstract class org.codehaus.jackson.map.SerializerProvider
                          -- (NullPointerException) null
                          null
                          java.lang.NullPointerException
                          at org.aspectj.weaver.UnresolvedType.forSignature(Unr esolvedType.java:361)

                          Comment

                          Working...
                          X