我正在使用Spring和MongoDB java驱动程序,我试图拦截mongo DBCursor对象上的所有调用,以便在执行之前查看查询。
我一直在尝试使用外部jar的aspject-maven-plugin来做这件事。
http://mojo.codehaus.org/aspectj-maven-plugin/weaveJars.html
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.4</version>
<configuration>
<verbose>true</verbose>
<privateScope>true</privateScope>
<complianceLevel>1.5</complianceLevel>
<weaveDependencies>
<weaveDependency>
<groupId>org.mongodb</groupId>
<artifactId>>mongo-java-driver</artifactId>
</weaveDependency>
</weaveDependencies>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
我已经在使用Spring AOP并在java代码中配置了aspecj
@EnableAspectJAutoProxy
然后我将以下内容添加到使用@Aspect注释的类中。 (其他拦截在我项目的源代码中的自定义类上正常工作)
@Pointcut("execution(* com.mongodb.DBCursor..*.*(..))")
public void interceptAndLog(ProceedingJoinPoint invocation){
_loggingService.Info("intercepted DBCursor");
}
我也尝试用@Before替换@Pointcut,但都没有工作。
提前致谢,
罗南