problems with Native AspectJ with Spring

789 views Asked by At

I am testing AspectJ compile time weaving with Spring 4 (once I get it to work, I want to use it in my projects). I have the following service class:

@Service
public class HelloService {

    public String sayHello(){       
        return sayHello2();
    }

    public String sayHello2(){
        return "Hello from AOP2!";
    }
}

And here's my AspectJ advice:

@Component
@Aspect
public class ExecutionTimeAdvice {

    @Around("execution(* com.senyume.aop.service..*(..))")
    public Object doBasicProfiling(ProceedingJoinPoint pjp) throws Throwable {

        long startTime = System.nanoTime();
        Object retVal = pjp.proceed();
        long endTime = System.nanoTime();

        long duration = (endTime - startTime);

        logger.info("Method " + pjp.getSignature() + " took " + (duration/1000000.0) + " ms)");

        return retVal;
    }
}

I am trying to enable AspectJ Compile time weaving according to Spring documentation. Since I am using annotations, I tried to follow advice mentioned in this thread.

When I run the application, I don't see the advice being applied to sayHello2(). What am I missing? What am I doing wrong here?

Full source code on github

1

There are 1 answers

4
kriegaex On BEST ANSWER

Your Gradle build uses the Java compiler to build the project. How about actually using the AspectJ compiler? That would help a lot if you want to use AspectJ. ;-)

You can use the Gradle AspectJ plugin.