Announcement Announcement Module
No announcement yet.
Run Advice before execution of Spring method. Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Run Advice before execution of Spring method.

    I would like a Pointcut that would run before methods in org.springframework.jdbc.core.JdbcTemplate. I have tried everything but I cannot get the Pointcut down. Please help.

    Currently I have @Pointcut("execution(* *org.springframework.jdbc.core.JdbcTemplate.*(..)) ").

  • #2
    Spring only advices bean it knows about. So if you don't define the JdbcTemplate inside the application context but construct a new one in your class it isn't going to be intercepted.


    • #3
      Below is the code I want to advise.

      public class JdbcProductDao extends JdbcDaoSupport implements ProductDao
      List<Product> products = getJdbcTemplate().query("select id,
      I want to run advice when the .query method is called


      • #4
        That is not going to be adviced. The JdbcTemplate is created internally to the DaoSupport class and not inside a spring application context. So spring doesn't know about that instance, so cannot intercept it.

        Either inject a JdbcTemplate (remove the JdbcDaoSupport class dependency create a construct which takes a template and inject it) or switch to loadtime weaving.


        • #5
          Marten Deinum,

          Back in this thread you suggested wrapping the data source to log SQL executed. How would one go about this?

          I would perfer not to use full blown AspectJ and load time weaving if possible.