내 프로젝트에서 봄과 ibatis를 사용합니다. 여기에 제 질문이 있습니다.타사 클래스를 pointcut 할 수 있습니까?
add/update/delete
과 같은 모든 변경 사항을 추적하고 표 T_TRACE_LOG
에 기록하고자합니다. 표의 열은 operation_type, object_type, log_content, log_date
입니다. AOP의 내 마음에 와서 내가 자동으로이 과정을 원
"add", "customer", "name='andy',age=23,...", 2012-06-14 17:04:57.410
log_content는 Customer.toString()
에서 온다 : 여기
일부는 이고 일부는 insertCustomer()
이고 다른 일부는 createCustomer()
을 사용하기 때문에 클라이언트 코드를 제어 할 수 없습니다. 그러나 그들 모두는 마침내 getSqlMapClientTemplate().insert("inserCustomer", Customer)
라고 불렀다. 그래서 getSqlMapClientTemplate().insert()
에 pointcut하여 모두 일치 시키길 원합니다. 여기
<aop:pointcut expression="execution(* com.xxx.CustomerDaoImpl.insert(..))" id="logPointCut"/>
때문에 : 나는 다음과 같이 표현을 변경하는 경우
<aop:pointcut expression="execution(* org.springframework.orm.ibatis.SqlMapClientTemplate.insert(..))" id="insertLogPointCut"/>
의미가 있습니다 바이트 코드 기반의 소스 코드이므로 ibatis 클래스에서 pointcut하는 것은 불가능하다고 생각합니다. 그것이 틀렸다면, 어떻게 내 상황을 처리 할 수 있습니까? (이것은 자바의 동적 프록시를 사용하고 있기 때문에) 봄
<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>
봄에 의해 클라이언트 템플릿 클래스가 인스턴스화됩니까? –
예, 스프링의 ioc로 인스턴스화되었습니다. SqlMapClientTemplate은 org.springframework.orm.ibatis.SqlMapClientFactoryBean을 가리키는 참조 "sqlMapClient"와 함께 CustomerDaoImpl에 삽입됩니다. –
주석이 아닌 질문에 정보를 추가하십시오. –