Search code examples
aopspring-aopaspect

Aspect not work with enhancerBySpringCGLIB


Faced with problem. Some fields in my classes are injected and in debugger i can see something like this: enter image description here

Problem begins when I am trying to map @Aspect to one of methods defined in SettingService. Like this:

@Aspect
public class SettingsAspect
{
    @AfterReturning(pointcut = "execution( * package.SettingsService.method(..))", returning = "result")
    public void profilingSettingsAdvice(JoinPoint joinPoint, String result)
    {
        System.out.println(joinPoint.getArgs());
    }

}

My service looks like this:

@Service
@Transactional
public class SettingsService
{    
    @Cacheable(value = "DefaultSettingsCache", key = "#root.methodName")
    public int method()
    {
        return 1;
    }
}

Don't know why, aspect isn't called after method() execution. Mystery is that aspect works ok with other classes/ What does it mean when class is injected with type Blablabla$$EnhancerBySpringCGLIB? Thank you.


Solution

  • Your advice only matches methods returning a String, but your method returns an int.