Results 1 to 4 of 4

Thread: Static Crosscutting - Introduction question

  1. #1

    Default Static Crosscutting - Introduction question

    I have declared the following aspect in aop.xml

    ControllerStatsAspect.java
    Code:
    @Aspect
    public class ControllerStatsAspect
    {
    	private Log log = LogFactory.getLog(getClass());
    
    	@DeclareMixin("com.simple.web.*Controller")
    	public Statsable statsableMixin(Object statsObj)
    	{
    		log.info("STATS: Mixin: " + statsObj);
    
    		return new StatsableDefaultImpl(statsObj);
    	}
    
    	@Before("execution(public * com.simple.web.*Controller.*(..)) && this(Statsable)")
    	public void increment(Statsable statsObj)
    	{
    		log.info("STATS: increment: " + statsObj);
    	}
    
    	@After("execution(public * com.simple.web.*Controller.*(..)) && this(Statsable)")
    	public void report(Statsable statsObj)
    	{
    		log.info("STATS: reports: " + statsObj);
    	}
    }
    aop.xml
    Code:
    <aspectj>
    
    	<aspects>
    
    	      <!-- declare three existing aspects to the weaver -->
    	      <aspect name="com.simple.aspect.stats.ControllerStatsAspect"/>
    
    	</aspects>
    
    	<weaver options="-verbose">
                  <include within="com.simple..*"/>
    
                  <!-- Do not weave types within the "CGLIB" generated package -->
                  <exclude within="*..*EnhancerByCGLIB*..*"/>
    
    	      <exclude within="*..*.*$$EnhancerByCGLIB$$*"/>
    
    	      <exclude within="*..*.*$$FastClassByCGLIB$$*"/>
           </weaver>
    
    </aspectj>
    I can see the log messages generated by ControllerStatsAspect.increment() and ControllerStatsAspect.reports() and both with null statsObj. But I never see any log message generated by the statsableMixin() method. I assume that explain why increment() and reports() log messages have a null statsObj object. I have two Controller classes under the com/simple/web folder and the web application is working without throwing any exceptions.

    Any idea why method statsableMixin() never get called?
    Last edited by zollen; Feb 21st, 2010 at 08:57 PM.

  2. #2
    Join Date
    Jun 2006
    Location
    SF Bay Area, California
    Posts
    524

    Default

    I am little surprised that you didn't get errors for not binding statsObj in your advice. You will need to change this(Statsable) to this(statsObj).

    -Ramnivas
    Ramnivas Laddad (Follow me on Twitter)
    AspectJ in Action: Enterprise AOP with Spring Applications (2nd edition). Now available!

  3. #3

    Default

    Quote Originally Posted by ramnivas View Post
    I am little surprised that you didn't get errors for not binding statsObj in your advice. You will need to change this(Statsable) to this(statsObj).

    -Ramnivas
    Thanks. I didn't get any errors.

  4. #4

    Default

    Quote Originally Posted by ramnivas View Post
    I am little surprised that you didn't get errors for not binding statsObj in your advice. You will need to change this(Statsable) to this(statsObj).

    -Ramnivas
    Thanks for your help. It works magically!!!!
    Last edited by zollen; Feb 22nd, 2010 at 07:19 PM.

Posting Permissions

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