- 创建bean-aop-xml.xml配置文件,定义Student Bean和AOP切面配置 - 实现Log通知类,提供前置通知功能用于日志记录 - 将Student类从di包移动到aop.xml包下进行重构 - 添加Test测试类,验证AOP切入点和前置通知的正确执行 - 配置AOP切点表达式,拦截com.ssm.aop.xml包下所有方法调用 - 实现完整的AOP XML配置方案,支持方法执行前的日志输出功能main
parent
8343420ba9
commit
4024266cb7
@ -0,0 +1,14 @@
|
||||
package com.ssm.aop.xml;
|
||||
|
||||
import org.aspectj.lang.JoinPoint; // 必须导入这个!
|
||||
|
||||
public class Log {
|
||||
// 前置通知:在目标方法执行前执行
|
||||
public void beforeAdvice(JoinPoint joinPoint) {
|
||||
// 获取目标类名
|
||||
String className = joinPoint.getTarget().getClass().getName();
|
||||
// 获取目标方法名
|
||||
String methodName = joinPoint.getSignature().getName();
|
||||
System.out.println("前置通知:模拟日志记录...目标类是:" + className + ",被切入通知的目标方法为:" + methodName);
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
package com.ssm.di;
|
||||
package com.ssm.aop.xml;
|
||||
|
||||
public class Student {
|
||||
// 学生核心属性
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in new issue