我想在 Grails 2.2.1 中使用spring
andlog4jdbc
来捕获 jdbc 信息,但它不起作用并且返回错误。
以下是中的log4j
配置config.groovy
:
info 'jdbc.sqlonly','jdbc.sqltiming';
这是 Grails spring dsl (resourcec.groovy):
beans = {
xmlns aop:"http://www.springframework.org/schema/aop"
aop{
config("proxy-target-class":true)
}
log4jdbcInterceptor(net.sf.log4jdbc.DataSourceSpyInterceptor)
dataSourceLog4jdbcAutoProxyCreator(org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator){
interceptorNames ="log4jdbcInterceptor"
beanNames = ["dataSource"]
}
和DataSourceSpyInterceptor.java
public class DataSourceSpyInterceptor implements MethodInterceptor {
private RdbmsSpecifics rdbmsSpecifics = null;
private RdbmsSpecifics getRdbmsSpecifics(Connection conn) {
if(rdbmsSpecifics == null) {
rdbmsSpecifics = DriverSpy.getRdbmsSpecifics(conn);
}
return rdbmsSpecifics;
}
public Object invoke(MethodInvocation invocation) throws Throwable {
Object result = invocation.proceed();
if(SpyLogFactory.getSpyLogDelegator().isJdbcLoggingEnabled()) {
if(result instanceof Connection) {
Connection conn = (Connection)result;
return new ConnectionSpy(conn,getRdbmsSpecifics(conn));
}
}
return result;
}
}