AOP-AspectJ-基于XML的实现——各种通知
来源:互联网 发布:js给集合添加元素 编辑:程序博客网 时间:2024/05/29 17:31
AOP-AspectJ-基于XML的实现——各种通知
Spring AOP-AspectJ-基于XML的实现各种通知
切面类
package com.hk.spring.xml;import org.aspectj.lang.JoinPoint;import org.aspectj.lang.ProceedingJoinPoint;import org.aspectj.lang.annotation.After;import org.aspectj.lang.annotation.AfterReturning;import org.aspectj.lang.annotation.AfterThrowing;import org.aspectj.lang.annotation.Around;import org.aspectj.lang.annotation.Aspect;import org.aspectj.lang.annotation.Before;import org.aspectj.lang.annotation.Pointcut;/** * 定义一个简单的POJO类作为切面类 * @author 浪丶荡 * @param <throwing> * *///切面类public class MyAspect<throwing> { /** * 前置通知 */ public void before(){ System.out.println("前置方法"); } /** * 前置通知2 */ public void before(JoinPoint j){ System.out.println("前置方法"+j); } /** * 后置通知 */ public void afterReturing(){ System.out.println("后置方法执行 "); } /** * 后置通知2 */ public void afterReturing(String result){ System.out.println("后置方法执行 result="+result); } /** * 环绕通知 */ public String around(ProceedingJoinPoint p){ Object result = null; System.out.println("目标方法执行前"); try { //执行目标方法 result = p.proceed(); } catch (Throwable e) { e.printStackTrace(); } System.out.println("目标方法执行后"); return ((String) result).toLowerCase(); } /** * 异常通知 */ public void afterThrowing(Exception ex){ System.out.println("afterThrowing执行,异常是:"+ex.getMessage()); } /** * 异常通知2 */ public void afterThrowing(){ System.out.println("afterThrowing执行,异常是:"); } /** * 最终通知 */ public void after(){ System.out.println("最终通知方法"); }}
配置文件
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd"> <!-- 注册目标对象 --> <bean id="someService" class="com.hk.spring.xml.ISomeServiceImpl"></bean> <!-- 注册切面 --> <bean id="myAspect" class="com.hk.spring.xml.MyAspect"></bean> <!-- aop配置 --> <aop:config> <!-- 切入点表达式 --> <aop:pointcut expression="execution(* *..ISomeService.doFirst(..))" id="doFirstPointcut"/> <aop:pointcut expression="execution(* *..ISomeservice.doSecond(..))" id="doSecondPointcut"/> <aop:pointcut expression="execution(* *..ISomeservice.doThird(..))" id="doThirdPointcut"/> <!-- 切面 --> <aop:aspect ref="myAspect"> <!-- 前置通知 pointcut-ref指定织入点--> <aop:before method="before" pointcut-ref="doFirstPointcut"/> <!-- 指定通知(有参数) pointcut-ref指定织入点--> <aop:before method="before(org.aspectj.lang.JoinPoint)" pointcut-ref="doFirstPointcut"/> <!-- 最终通知 --> <aop:after method="after" pointcut-ref="doFirstPointcut"/> <!-- 后置通知 含参 --> <aop:after-returning method="afterReturing(java.lang.String)" pointcut-ref="doFirstPointcut" returning="result"/> <!-- 后置通知 --> <aop:after-returning method="afterReturing" pointcut-ref="doFirstPointcut"/> <!-- 环绕通知 不需要加参数org.aspectj.lang.ProceedingJoinPoint因为自身已经包含了--> <aop:around method="around" pointcut-ref="doThirdPointcut"/> <!-- 异常通知 --> <aop:after-throwing method="afterThrowing" pointcut-ref="doSecondPointcut"/> <!-- 异常通知含参 --> <aop:after-throwing method="afterThrowing(java.lang.Exception)" pointcut-ref="doSecondPointcut" throwing="ex"/> </aop:aspect> </aop:config></beans>
0 0
- AOP-AspectJ-基于XML的实现——各种通知
- AspectJ 基于注解的实现各种通知
- Spring Aop(二)——基于Aspectj注解的Aop简单实现
- 基于AspectJ实现AOP
- aop 通过xml实现 (各种通知)
- AspectJ 基于注解的实现前置通知
- SSM框架项目搭建系列(六)—Spring AOP之基于XML的声明式AspectJ
- AspectJ对AOP的实现(xml)
- 基于@AspectJ的AOP
- 基于@AspectJ的AOP
- spring aop 环绕通知 基于@aspectJ
- Spring整理系列(14)——基于注解的AspectJ风格实现spring AOP
- (十)Spring详解——基于@AspectJ的AOP
- Spring -- 基于XML的AOP通知配置
- JAVAWEB开发之Spring详解之——AOP底层剖析(基于JDK和cglib)、Spring中的AOP以及基于AspectJ的AOP实现、Spring的JDBCTemplate详解
- Spring AOP技术(基于AspectJ)的XML开发
- 基于AspectJ的XML方式进行AOP开发
- AOP的annotation实现方式是基于AspectJ的实现
- my_MakeFile
- Android应用性能优化之Apk瘦身机制
- React 精华一页纸
- 迷宫的最短路问题(水+BFS宽搜)
- C# 操作Sql Server 学习总结
- AOP-AspectJ-基于XML的实现——各种通知
- redis加减操作
- js判断方法变量是否存在
- 设计一个具有GetMin功能的栈
- Redis实现高并发下的抢购、秒杀功能
- 素数打表(小模板)
- 【ES6】16.generator函数的语法 10.(1)异步操作的同步化表达
- 3天速成混合app开发_01环境部署
- 排序算法