1.记录日志的操作步骤(采用环绕通知的方式)

2.写记录日志的aop组件

LoggerBean.java就是普通的类

3.类中写个方法

public Object loggerOperation(ProceedingJoinPoint pjp) throws Throwable {
//ProceedingJoinPoint为连接点对象
Object obj = pjp.proceed();// 执行目标组件的目标方法
// ---------在目标方法之后执行-------------
// 获取当前指行的类型名
String className = pjp.getTarget().getClass().getName();
// 获取当前执行的方法名
String methodName =pjp.getSignature().getName();
System.out.println("你执行了" + className + "类的"+ methodName + "方法!");
return obj;
}

4.在spring配置文件中配置aop

完整版的配置文件:

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee"
xsi:schemaLocation="
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd">

5.测试

@Test
public void test1(){
String[] conf = {"applicationContext.xml"};
ApplicationContext ac =new ClassPathXmlApplicationContext(conf);
AbcAction abc=(AbcAction) ac.getBean("abc");
abc.getStrng();
}