问题描述
我正在用Spring 4测试AspectJ的编译时编织(一旦我开始使用它,我想在我的项目中使用它).我有以下服务类别:
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!";
}
}
这是我的AspectJ建议:
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;
}
}
我正在尝试根据 Spring文档.由于我使用的是注释,因此我尝试遵循在这个线程中.
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.
当我运行应用程序时,我看不到将建议应用于sayHello2().我想念什么?我在这里做什么错了?
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?
完整的源代码在github上
推荐答案
您的Gradle构建使用Java编译器来构建项目.实际使用AspectJ编译器怎么样?如果您想使用AspectJ,那会很有帮助. ;-)
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. ;-)
您可以使用 Gradle AspectJ插件.
这篇关于Spring Native AspectJ的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!