Announcement Announcement Module
Collapse
No announcement yet.
Advice Not getting applied Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Advice Not getting applied

    It has been a while since I applied AspectJ to Spring beans. I have the following code:

    Code:
    package com.demo.aop;
    
    import org.aspectj.lang.ProceedingJoinPoint;
    import org.aspectj.lang.annotation.Around;
    import org.aspectj.lang.annotation.Aspect;
    import org.aspectj.lang.annotation.Pointcut;
    
    @Aspect
    public class DemoTracingAspect {
    	@Pointcut("execution(public * *(..))")
    	public void tracing() {}
    
    	@Pointcut("within(com.demo..*)")
    	public void inDemo() {}
    
    	@Around("tracing() && inDemo()")
    	public Object trace(ProceedingJoinPoint pjp) throws Throwable {
    		// Log log = LogFactory.getLog(pjp.getClass());
    		String invocationDescription = getInvocationDescription(pjp);
    		// log.trace("Entering " + invocationDescription);
    		System.out.println("Entering " + invocationDescription);
    		try {
    			Object rval = pjp.proceed();
    			// log.trace("Exiting " + invocationDescription);
    			System.out.println("Exiting " + invocationDescription);
    			return rval;
    		} catch (Throwable ex) {
    			// log.trace("Exception thrown in " + invocationDescription, ex);
    			System.out.println("Exception thrown in " + invocationDescription
    					+ "\n" + ex.getStackTrace());
    			throw ex;
    		}
    	}
    
    	/**
    	 * Return a description for the given method invocation.
    	 * 
    	 * @param invocation
    	 *            the invocation to describe
    	 * @return the description
    	 */
    	protected String getInvocationDescription(ProceedingJoinPoint thisJoinPoint) {
    		return "method '" + thisJoinPoint.getSignature().getName()
    				+ "' of class ["
    				+ thisJoinPoint.getSignature().getClass().getName() + "]";
    	}
    }
    And the following Spring config:

    Code:
    <context:annotation-config/>
    <aop:aspectj-autoproxy proxy-target-class="true"/>
    <bean id="tracingAspect" class="com.demo.aop.DemoTracingAspect"/>
    I have tried with & without proxy-target-class and no matter what the Aspect never gets applied.

    Thoughts?
    Last edited by difranr; Nov 24th, 2009, 09:02 AM.

  • #2
    Show an example of bean method call that is not advised.

    Comment

    Working...
    X