Spring AOP demo

时间:2021-12-06 05:14:31
【文件属性】:
文件名称:Spring AOP demo
文件大小:6KB
文件格式:RAR
更新时间:2021-12-06 05:14:31
spring aop 基于注解与 XML 配置文件两种形式的 AOP demo。 基于 xml 配置文件的 aop 管理 ```xml <!-- 配置切面的bean --> <!-- 配置切点表达式 --> <!-- 配置切面 --> <!-- 配置通知 --> ``` Java 类 ```java public class LoggingAspect { public void beforeMethod(JoinPoint joinPoint) { System.out.println("在目标方法执行之前执行" + ", 要拦截的方法是:" + joinPoint.getSignature()); } public Object aroundMethod(ProceedingJoinPoint joinPoint) throws Throwable { Object[] args = joinPoint.getArgs(); // 判断目标方法参数,满足条件修改参数值 if(" See You Again".equals(args[0])) { args[0] = " See You Again ..."; } // 在目标方法执行之前执行,相当于前置通知 System.out.println("这是一个前置通知"); // 执行目标方法 Object result = joinPoint.proceed(args); // 在目标方法执行之后之后,相当于后置通知 System.out.println("这是一个后置通知"); return result; } }
【文件预览】:
spring-aop
----pom.xml(824B)
----src()
--------main()
----.gitignore(249B)

网友评论