Spring AOP does not intercept JMS MessageListener onMesage() call

203 views Asked by At

I am trying to intercept JMS MessageListener onMessage() method using Spring AOP, but my advice is not getting called. I have created an annotation @LoggingInfo:

@Target (ElementType.METHOD)
@Retention (RetentionPolicy.RUNTIME)
public @interface LoggingInfo {        
}

Aspect class : I have also tried with the commented ponitcut definition but still advice is not getting called.

@Aspect
@Component
public class LoggingAspect {
    
    @Pointcut("@annotation(LoggingInfo)")
    private void annotationPointCut() {
    }
    
    //@Pointcut ("execution(* *(..))”)
    //@Pointcut ("execution( void *.onMessage (javax.jms.Message))")
    @Pointcut("execution( void javax.jms.MessageListener.onMessage(javax.jms.Message))")
    private void onMessagePointCut() {
    }
    
    @AfterReturning("onMessagePointCut() && annotationPointCut()")
    public void loggingAdvice(JoinPoint jp ) {
         System.out.println("logging advice method called successfully");
    }    
}

MessageReceiver.java

@Component
public class MessageReceiver implements MessageListener {
    @Override
    @LoggingInfo
    public void onMessage(Message message) {
          System.out.println("Jms message processed successfully");
    }
}

All other configuration to setup the application are done properly and onMessage() is processing the incoming message successfully. Also @ComponentScan annotations is mention in application class to scan all the beans.

Is there anything can be done to achieve this using Spring AOP?

0

There are 0 answers