title: Intercepting MongoDB calls using AspectJ in a Spring project
body: <p>I am using Spring and the MongoDB java driver and I am trying to intercept all calls on the mongo DBCursor object to view queries before they get executed. </p>
  
  <p>I've been trying to do this using the aspject-maven-plugin for external jars.</p>
  
  <p><a href="http://mojo.codehaus.org/aspectj-maven-plugin/weaveJars.html" rel="nofollow">http://mojo.codehaus.org/aspectj-maven-plugin/weaveJars.html</a></p>
  
  <pre><code>&lt;plugin&gt;
      &lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt;
      &lt;artifactId&gt;aspectj-maven-plugin&lt;/artifactId&gt;
      &lt;version&gt;1.4&lt;/version&gt;
      &lt;configuration&gt;
           &lt;verbose&gt;true&lt;/verbose&gt;
        &lt;privateScope&gt;true&lt;/privateScope&gt;
        &lt;complianceLevel&gt;1.5&lt;/complianceLevel&gt;
          &lt;weaveDependencies&gt;
          &lt;weaveDependency&gt;
            &lt;groupId&gt;org.mongodb&lt;/groupId&gt;
            &lt;artifactId&gt;&gt;mongo-java-driver&lt;/artifactId&gt;
          &lt;/weaveDependency&gt;
        &lt;/weaveDependencies&gt;
      &lt;/configuration&gt;
      &lt;executions&gt;
        &lt;execution&gt;
          &lt;goals&gt;
            &lt;goal&gt;compile&lt;/goal&gt;
          &lt;/goals&gt;
        &lt;/execution&gt;
      &lt;/executions&gt;
    &lt;/plugin&gt;
  </code></pre>
  
  <p>I am already using Spring AOP and have aspecj configured in java code</p>
  
  <pre><code>@EnableAspectJAutoProxy
  </code></pre>
  
  <p>I am then adding the following to a class which uses the @Aspect annotation. (Other intercepts are working fine on custom classes which are in the source code of my project)</p>
  
  <pre><code>@Pointcut("execution(* com.mongodb.DBCursor..*.*(..))")
  public void interceptAndLog(ProceedingJoinPoint invocation){
  
            _loggingService.Info("intercepted DBCursor");
  
   }
  </code></pre>
  
  <p>I have also tried replacing @Pointcut with @Before but neither work.</p>
  
  <p>Thanks in advance,</p>
  
  <p>Ronan</p>