Spring AOP切面日志Demo 配置文件方式
来源:互联网 发布:ps有没有mac版 编辑:程序博客网 时间:2024/06/03 16:32
第一步:配置applicationContext.xml文件:
<bean id="logAopBean" class="com.demo.common.aop.LogAop"></bean> <aop:config> <aop:aspect id="logAspect" ref="logAopBean"> <aop:pointcut expression="execution(* com.demo..*(..))" id="allMethod"/> <aop:before method="before" pointcut-ref="allMethod" /> <aop:after-throwing method="afterThrowing" pointcut-ref="allMethod" /> <aop:after-returning method="afterReturn" pointcut-ref="allMethod" /> <aop:after method="after" pointcut-ref="allMethod" /> </aop:aspect> </aop:config>
第二步:日志处理类的写法:
/** * LogAop.java * * Shanghai NTT DATA Synergy Software Co., Ltd. All Rights Reserved. * @author wyl * @date 2016-10-18 */ package com.demo.common.aop;import org.aspectj.lang.JoinPoint;import org.aspectj.lang.ProceedingJoinPoint;/** * @author wyl * @Description TODO * @date 2016-10-18 * */public class LogAop { public void before(JoinPoint call){ String className = call.getTarget().getClass().getName(); String methodName = call.getSignature().getName(); System.out.println("开始执行:"+className+"."+methodName+"()方法..."); } public void afterThrowing(JoinPoint call){ String className = call.getTarget().getClass().getName(); String methodName = call.getSignature().getName(); System.out.println(className+"."+methodName+"()方法抛出了异常..."); } public void afterReturn(JoinPoint call){ String className = call.getTarget().getClass().getName(); String methodName = call.getSignature().getName(); System.out.println(className+"."+methodName+"()方法正常执行结束..."); } public void after(JoinPoint call){ String className = call.getTarget().getClass().getName(); String methodName = call.getSignature().getName(); System.out.println(className+"."+methodName+"()最终执行步骤(finally)..."); } /*//用来做环绕通知的方法可以第一个参数定义为org.aspectj.lang.ProceedingJoinPoint类型 public Object doAround(ProceedingJoinPoint call) throws Throwable { Object result = null; this.before(call);//相当于前置通知 try { result = call.proceed(); this.afterReturn(call); //相当于后置通知 } catch (Throwable e) { this.afterThrowing(call); //相当于异常抛出后通知 throw e; }finally{ this.after(call); //相当于最终通知 } return result; }*/}原文链接:原文链接
阅读全文
0 0
- Spring AOP切面日志Demo 配置文件方式
- spring aop切面编写demo
- Spring整理12 -- 面对切面(AOP)2 -- 配置文件的方式实现AOP
- Spring整理12 -- 面对切面(AOP)2 -- 配置文件的方式实现AOP
- Spring-通过xml配置文件实现切面(AOP)
- Spring aop切面做日志处理操作
- spring aop 切面记录log4j日志
- Spring AOP(通过配置文件方式)
- Spring AOP基础 配置文件方式
- spring-aop 配置文件方式实现
- Spring-AOP:基于配置文件方式的AOP
- aop切面记录日志
- AOP切面管理日志的两种方式
- Spring 使用Aop 做切面日志,和权限。
- spring AOP切面编程在方法执行前后切入日志
- java ssh spring aop 切面编程 操作日志
- spring aop切面应用,记录日志、请求处理耗时
- Spring—AOP实践,利用切面记录用户操作日志
- zookeeper使用说明
- java--面向对象1-18例题的test
- DC-DC电源PCB设计指南
- 在TextView中使用了ClickableSpan后,禁止TextView滑动。
- php 对象转数组
- Spring AOP切面日志Demo 配置文件方式
- 增量型PID算法
- unity3d NGUI笔记1
- 知识总结
- [微信小程序]星级评分和展示(详细注释附效果图)
- 关于Dotween的文章
- 如何在 Git 里撤销(几乎)任何操作
- 知识、数据与推理
- 人工智能与艺术的未来
原创粉丝点击
热门IT博客
热门问题
老师的惩罚
人脸识别
我在镇武司摸鱼那些年
重生之率土为王
我在大康的咸鱼生活
盘龙之生命进化
天生仙种
凡人之先天五行
春回大明朝
姑娘不必设防,我是瞎子
电脑滑动失灵怎么办
sim卡槽坏了怎么办
手机进水后跳屏怎么办
手机屏幕烧坏了怎么办
华为手机屏幕不灵敏怎么办
手机屏幕有残影怎么办
su卡怎么办
su卡顿怎么办
苹果8玩吃鸡卡怎么办
玩吃鸡手机卡顿怎么办
玩手机游戏卡怎么办
苹果停用怎么办
iphone4锁死了怎么办
苹果手机屏锁死怎么办
苹果七死机怎么办
苹果七白屏死机怎么办
苹果电脑黑屏了怎么办
iphone7不能开机怎么办
苹果五黑屏怎么办
苹果8黑屏怎么办
苹果ipad总闪退怎么办
手机按键不管用怎么办
苹果se黑屏怎么办
iphonex黑屏怎么办
iphone6黑屏怎么办啊
手机屏滑打不开怎么办
无法滑屏怎么办
手机屏幕不能按怎么办
vivox7黑屏了怎么办
iphone屏幕点不亮怎么办
iphone慢慢黑屏怎么办
苹果电脑无法开机怎么办
手机摔出黑块怎么办
苹果6换屏后松怎么办
桌面太乱怎么办
手机乱跳乱点怎么办
iphone6黑屏了怎么办
3岁尿床怎么办
苹果七触屏不好怎么办
苹果手机屏幕失灵怎么办
手机不能充电怎么办