我正在用Spring 4测试AspectJ的编译时编织(一旦我开始使用它,我想在我的项目中使用它)。我有以下服务类别:
@Service public class HelloService { public String sayHello(){ return sayHello2(); } public String sayHello2(){ return "Hello from AOP2!"; } }
这是我的AspectJ建议:
@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; } }
我试图根据Spring文档http://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/#aop-aj-configureb 启用AspectJ编译时编织。由于我使用的是注释,因此我尝试遵循本主题中提到的建议。
当我运行该应用程序时,我看不到该建议已应用于sayHello2()。我想念什么?我在这里做错了什么?
github上的完整源代码https://github.com/jigishpa/spring-samples/tree/master/aop/hello