spring如何做日志?(日志经典方法)
logAdvice类:
配置如下:
logAdvice类:
public class LogAdvice {
public void log(){
System.out.println("日志记录");
}
public void afterLog() {
System.out.println("after日志记录");
}
配置如下:
<bean id="hibernateUtil" class="com.cs.util.HibernateUtil" ></bean>
<bean id="teamDao" class="com.cs.dao.TeamDaoImpl">
<property name="hibernateUtil" ref="hibernateUtil" />
</bean>
<bean id="personDao" class="com.cs.dao.PersonDaoImpl">
<property name="hibernateUtil" ref="hibernateUtil" />
<property name="teamDao" ref="teamDao" />
</bean>
<bean id="logAdvice" class="com.cs.advice.LogAdvice" />
<aop:config>
<aop:pointcut id="allmethod" expression="execution(* add*(..))" />
<aop:pointcut id="updatemethod" expression="execution(* update*(..))" />
<aop:aspect id="log" ref="logAdvice" > //把日志类横切到所有的add,update方法中去
<aop:before pointcut-ref="allmethod" method="log" /> //add方法执行后调用LogAdvice类的log方法
<aop:after pointcut-ref="updatemethod" method="afterLog"/> //update*方法执行后调用LogAdvice的afterLog方法
</aop:aspect>
</aop:config>