I use spring and ibatis in my project, here is my question.
I want to trace all changes like add/update/delete
and log them into table T_TRACE_LOG
. The table has columns: operation_type, object_type, log_content, log_date
.
Here is an example record:
"add", "customer", "name='andy',age=23,...", 2012-06-14 17:04:57.410
The log_content comes from Customer.toString()
, I want this process automatically, so the AOP comes into my mind.
I can't control the client code, because some uses addCustomer()
and some uses insertCustomer()
and others use createCustomer()
. But all of them called getSqlMapClientTemplate().insert("inserCustomer", Customer)
at last. So I want to pointcut on getSqlMapClientTemplate().insert()
to match them all.
Here is my trying, but it doesn't work:
<aop:pointcut expression="execution(* org.springframework.orm.ibatis.SqlMapClientTemplate.insert(..))" id="insertLogPointCut"/>
It works If I change the expression as below:
<aop:pointcut expression="execution(* com.xxx.CustomerDaoImpl.insert(..))" id="logPointCut"/>
Because AOP compiles the "pointcut information" into class bytecode based on source code, so I think it's impossible to pointcut on the ibatis class. If it's wrong, how to handle my situation?
Here is the configuration:
<aop:aspectj-autoproxy proxy-target-class="true"/>
<bean id="traceLogger" class="com.xx.TraceLogger"/>
<aop:config>
<aop:pointcut expression="execution(* com.xx.CustomerDaoImpl.insert(..))" id="insertLogPointCut"/>
<aop:aspect id="logAspect" ref="traceLogger">
<aop:after-returning method="logAfterReturning" pointcut-ref="insertLogPointCut"/>
</aop:aspect>
</aop:config>