0
votes

I am working on AspectJ AOP implementation on spring MVC application. I have written Aspect java class where I am trying to intercept join points for all the methods of one of the packages say com.xyz.services. But AOP always failed to interecept the methods of that package. Aspect is defined as follows -

@Pointcut("execution(* com.xyz.services..*.*(..))")
public void logBefore() {

}
@Before("logBefore()")
public void logHere(JoinPoint joinPoint) {
    System.out.println("In logHere ....");
    logger.info("logBefore is running ....");
    logger.info("hijacked ::::" + joinPoint.getSignature().getName());
    logger.info("joinPoint.getSignature().getDeclaringTypeName() ::::"
                    + joinPoint.getSignature().getDeclaringTypeName());
    logger.info("joinPoint.getSignature().getModifiers() ::::"
            + joinPoint.getSignature().getModifiers());
    logger.info("******************************************************");
}

I have enabled AOP in application-context.xml as follows -

<aop:aspectj-autoproxy proxy-target-class="true">
    <aop:include name='loggingAspect' />
</aop:aspectj-autoproxy>

When ever I am calling webservice the methods in the com.xyz.services get called but the Aspect method never get called.

I tried with different pointcuts but the aspect code never did not execute.

@Pointcut("execution(public * com.xyz.services.ManagerServiceImpl.*(..))")
public void logBefore() {
System.out.println("In Logbefore");}

@Pointcut("execution(public * com.xyz.services.*.*(..))")
public void logBefore() {
System.out.println("In Logbefore");
}    

I have added cglib dependency on pom.xml to enable cglib based proxies.

<dependency>
        <groupId>cglib</groupId>
        <artifactId>cglib</artifactId>
        <version>2.2.2</version>
    </dependency>

Can anyone help me out why this aspects are not working as expected?

1
Guys any input on these?GauravP
Probably there was no answer because of incomplete information. Can you prepare a little SSCCE, maybe on GitHub and including a Maven POM, in order to make your problem reproduceable? The pointcuts look okay, so either it is a configuration problem or the classes targeted by your advice are not Spring components or you it is a subtle package name issue in your classes. Without more info I can just hypothesise.kriegaex

1 Answers

0
votes

have you configured correctly the class with the annotation ?

@EnableAspectJAutoProxy(proxyTargetClass = true)