通过Spring AOP 拦截 SQL
来源:互联网 发布:qq飞车银天使逆光数据 编辑:程序博客网 时间:2024/05/22 07:52
sql 的重要性,开发人员都很清除,并不是所有人和时刻都记得log sql ,为了不侵入原来已经写好的代码,亦为了将来可以方便移走log,采用spring 的AOP 来记录log 是件很有意义的事情。配置如下
<bean id="theTracingBeforeAdvice" class="your.com.TracingBeforeAdvice"/>
<bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<property name="proxyTargetClass">
<value>true</value>
</property>
<property name="interceptorNames">
<list>
<value>theTracingBeforeAdvice</value>
</list>
</property>
<property name="beanNames">
<list>
<value>jdbcTemplate</value>
</list>
</property>
</bean>
<bean id="jdbcTemplate"
class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource">
<ref bean="dataSource" />
</property>
</bean>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost/mytest?useUnicode=true&characterEncoding=utf-8" />
<property name="username" value="root" />
<property name="password" value="123456" />
<property name="maxActive" value="100" />
<property name="maxIdle" value="30" />
<property name="maxWait" value="1000" />
<property name="defaultAutoCommit" value="true" />
<property name="removeAbandoned" value="true" />
<property name="removeAbandonedTimeout" value="60" />
</bean>
有一点是很重要,spring 自动代理默认为接口,如果要代理类,需要在属性中指出,如上面的粗体
实现类
public class TracingBeforeAdvice implements MethodBeforeAdvice {
private Logger logger = Logger.getLogger(TracingBeforeAdvice.class);
public void before(Method m, Object[] args, Object target) throws Throwable {
if (args != null) {
logger.warn( target.getClass().getName() + "." + m.getName() );
logger.warn(target.getClass().getName());
if (args.length>0)
{
for(int i=0;i<args.length;i++)
logger.warn( args[i]);
}
}
}
}
- 通过Spring AOP 拦截 SQL
- 通过spring的aop统一拦截Exception抛出自定义异常
- Spring AOP(拦截)
- Spring AOP 拦截
- Spring AOP 拦截
- Spring aop拦截器
- spring aop拦截action
- spring aop 拦截例子
- spring前置AOP拦截action
- spring AOP的异常拦截
- Spring AOP 异常拦截器
- spring 简单配置aop 拦截
- spring AOP的异常拦截
- Spring Aop 日志拦截器
- spring AOP的异常拦截
- spring aop拦截action配置
- spring AOP的异常拦截
- spring的aop拦截器
- WAP知识
- 平台的第二年
- 转 业务层中 被调用服务的遭遇事务回滚的处理 2方法
- SQL 里的CAST CONVERT学习
- Linux软件下载源码编程文章资料
- 通过Spring AOP 拦截 SQL
- windows+apache2.2.4+php5.2.5+mysql5.0+tomcat5.5整合
- 面向以用户活动为中心的网络社区发展新模式
- 为什么国内php人才这么少?
- 编程生成一个瓶子(2)
- 学习笔记
- 3d联客展示
- javascript去除空格
- 高光溢出(Blooming)