Search code examples
javaspring-bootaspectjjdbctemplate

JDBC Aspect pointcut not invoked


First, I am using an AspectJ Aspect in order to log execution time and request parameters from a JDBC template.

In my project, I have another Aspect which logs my service methods and this one is working fine.

I tried to reproduce the same configuration to catch JDBC Operations but my aspect is not invoked since I tried to execute my code in debug and I never reached my first breakpoint.

I saw that there are several issues on the same subject and I tried several of the solutions proposed but none of them worked in my case.

My aspect configuration for the Pointcut is the following:

@Aspect
@Slf4j
@Component
public class SQLLoggingAspect {

private static final DateTimeFormatter DATE_FORMATTER = DateTimeFormat.forPattern("yyyy-MM-dd");
private static final DateTimeFormatter  TIMESTAMP_FORMATTER  = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");

@Pointcut("execution(* org.springframework.jdbc.core.JdbcOperations.*(..))")
public void sqlMethods(){}

@Before(value = "sqlMethods()", argNames = "joinPoint")
public void log(JoinPoint joinPoint) throws Throwable {
    Object[] methodArgs = joinPoint.getArgs(),

I did not declare any AspectJ autoproxy since my first aspect is working without it and since Spring is supposed to handle it automatically as I understand.

I am not familiar with this kind of development. Maybe I am doing something dumb.


Solution

  • I found my issue. I had to set the autoproxy to catch SQL calls.

    I just used this:

    @EnableAspectJAutoProxy