problems with Native AspectJ with Spring

折月煮酒 提交于 2019-12-20 07:32:08

问题


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:


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.



来源:https://stackoverflow.com/questions/27075701/problems-with-native-aspectj-with-spring

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!