這是我applicationCotext.xml中的配置文件
aop:config
/aop:aspect
/aop:config
這是我的advices類
public class Advisor {
static Logger log = Logger.getLogger(Advisor.class);
public String information;
/**
*
*/
public Advisor() {
// TODO Auto-generated constructor stub
log.info("進入");
}
public void before(JoinPoint joinpoint){
information = "通知:"+joinpoint.getClass().getName()+"類的"+joinpoint.getClass().getMethods()+"開始執行";
log.info(information);
}
public void after(JoinPoint joinpoint){
information = "通知:"+joinpoint.getClass().getName()+"類的"+joinpoint.getClass().getMethods()+"執行完畢";
log.info(information);
}
public void exception(JoinPoint joinpoint){
information = "通知:"+joinpoint.getClass().getName()+"類的"+joinpoint.getClass().getMethods()+"出現異常";
log.info(information);
}
}
<!--將日志類注入到bean中。-->
<bean id="advices" class="com.sunyard.advice.Advisor"></bean>
<aop:config>
<aop:aspect id="log" ref="advices">
<aop:pointcut id="pointcut" expression="execution(* com.sunyard.cpjbxxShow.action.*.*(..))"/>
<aop:before pointcut-ref="pointcut" method="before"/>
<aop:after pointcut-ref="pointcut" method="after"/>
<aop:after-throwing pointcut-ref="pointcut" method="exception"/>
</aop:aspect>
</aop:config>