Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: New Spring Caching Not Working With AspectJ LTW

  1. #1
    Join Date
    Jan 2006
    Location
    South Africa, Cape Town
    Posts
    11

    Default 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. #2
    Join Date
    Dec 2011
    Posts
    6

    Default

    Hi

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

    Thank you.

  3. #3
    Join Date
    Jan 2005
    Location
    Bucharest, Romania
    Posts
    5,403

    Default

    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?
    Costin Leau
    SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
    http://twitter.com/costinl
    Please use [ c o d e ] [ / c o d e ] tags

  4. #4
    Join Date
    Jan 2006
    Location
    South Africa, Cape Town
    Posts
    11

    Default

    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. #5
    Join Date
    Dec 2011
    Posts
    6

    Default

    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 at 01:41 AM.

  6. #6
    Join Date
    Dec 2011
    Posts
    6

    Default

    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

  7. #7
    Join Date
    Jan 2006
    Location
    South Africa, Cape Town
    Posts
    11

    Default

    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>

  8. #8
    Join Date
    Dec 2011
    Posts
    6

    Default

    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.

  9. #9
    Join Date
    Jan 2006
    Location
    South Africa, Cape Town
    Posts
    11

    Default

    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.

  10. #10
    Join Date
    Dec 2011
    Posts
    6

    Default

    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"/>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •