Armando
Armando

Reputation: 1

Capture org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter.onMessage() invocation

I'm using AspectJ and AOP in a Spring-boot project in order create an external library to log some activities.

Although I have configured this pointcut:

@Pointcut("call(void org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter.onMessage(Message,Channel))")
     private void getEventOnMessage(){}

the aspect

 @Before(value="getEventOnMessage()")
    public  void getEventOnMessage(JoinPoint joinPoint){
        System.out.println("VOILA'");
    }

is not triggered.

Details:

package com.tim.sdp.timLogging.Aspects.handler;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;

    @Configuration
    @EnableAspectJAutoProxy
    @ComponentScan(basePackages="org.springframework.amqp.rabbit.listener.adapter")
    public class AppConfig {
        @Bean()
        public AspectForOnMessage myAspect() {
            return new AspectForOnMessage();
        }
    }

Aspect class implementation:

package com.tim.sdp.timLogging.Aspects.handler;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class AspectForOnMessage {

    @Pointcut("call(void org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter.onMessage(Message,Channel))")
    private void getEventOnMessage(){}

    @Before(value="getEventOnMessage()")
    public  void getEventOnMessage(JoinPoint joinPoint){
        System.out.println("VOILA'");
    }
}

Might you help me, please? It's the only event I can not capture. In this forum you can find another person with the same problem:

Spring forum link

Thank you in advance.

Upvotes: 0

Views: 530

Answers (1)

kriegaex
kriegaex

Reputation: 67407

Oh, a classical one!

As documented here, call() is not supported in proxy-based Spring AOP which you have configured in your application via @EnableAspectJAutoProxy. You need to switch from "AOP lite" to the full power of AspectJ as described there or stick with pointcuts really supported in Spring AOP.

Upvotes: 1

Related Questions