Results 1 to 3 of 3

Thread: Pointcut on Spring JDBC classes not working

  1. #1
    Join Date
    Sep 2010
    Posts
    19

    Default Pointcut on Spring JDBC classes not working

    I'm trying to create a pointcut on Spring JDBC classes.. specifically those that implement JdbcOperations.

    Code:
    @Pointcut("execution(* org.springframework.jdbc.core.JdbcOperations.*(..))")
        public void jdbcMethods() {}
    Then I try some around advice.

    Code:
    @Around("jdbcMethods()")
        public Object time(ProceedingJoinPoint pjp) throws Throwable {
            long start = System.currentTimeMillis();
            Object obj = pjp.proceed();
            long time = System.currentTimeMillis() - start;
            System.out.println(pjp.getSignature().getName() +" took "+ time +"ms");
            return obj;
        }
    But it doesn't work. If I switch the pointcut expression to one of my own interfaces, it works as intended. What is wrong here?

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,624

    Default

    And is the JdbcTemplate implementing that bean a spring managed bean or is it constructed INSIDE another spring managed bean?! I suggest a read of the AOP chapter regarding proxies and what can be proxied.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Sep 2010
    Posts
    19

    Default

    Great observation, my JdbcTemplate instance was within a spring-managed bean, but was not itself a spring-managed bean. Once I made that correction, everything works as I intended. Thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •