Search code examples
javaspringaopaspectjspring-aop

Aspectj: Advised method is not calling the Aspect method


I am trying to advice a method with pointcut.

All other pointcut are working, This is the aspect signature, and commented @Before pointcuts are the ones that work. But I am not sure why last bulkInsert pointcut is not working.

   //@Before("execution(public * com.service.dao.WorkStayDao.update(..))")
  // @Before("execution(public * com.workunit.WorkService.isSkipUpdateWorkUnit(..))")
    @Before("execution(public * com.service.dao.WorkGoDao.bulkInsert(..))")
        public void logMethodCall(JoinPoint jp) throws JsonProcessingException {}

WorkGoDao.bulkInsert() gets called from WorkStayDao.update() method.

update() signature is

public Work update(String userID, final Work workt)

bulkInsert() Signature is

public void bulkInsert(String UserId, Set<Work> work, SqlSession session)

WorkGoDao class is also marked as @Service.

My Aspect class is also annotated with all required Annotations

@Aspect
@Configuration
@EnableAspectJAutoProxy
public class ErrorLoggingAspect

Goal is that: bulkInsert Should call the logMethodCall() before execution.

I am not sure why methods from same packages are behaving differently on being advised. I have looked at all aspect related queries but can't find the solution. And the biggest issue that it's really hard to debug as no error logs are printed. I am using Intellij to run locally.

Am I missing any concept or something, any help will be really appreciated, even ways to debug.


Solution

  • I have found the issue with my code.

    The mistake I was making was Creating User managed object for the class WorkGoDao and WorkStayDao in calling classes. AOP looks for the bean in spring context, since mine were user created object and hence unavailable in Context.

    I fixed the issue by creating Spring managed object of WorkGoDao and WorkStayDao, for me an object with Field level @Autowired injection did the job. One can also create the setter or constructor injected object.