package com.hope.utils;

import org.aspectj.lang.ProceedingJoinPoint;

/**
* @author newcityman
* @date 2019/11/22 - 23:29
* 记录日志的类
*/
public class Logger {
/**
* 前置通知
*/
public void beforePrintLog(){
System.out.println("前置通知");
}

/**
* 后置通知
*/
public void afterReturningPrintLog(){
System.out.println("后置通知");
}

/**
* 异常通知
*/
public void afterThrowingPrintLog(){
System.out.println("异常通知");
}

/**
* 最终通知
*/
public void afterPrintLog(){
System.out.println("最终通知");
}

/**
* 环绕通知
*/
public Object aroundPrintLog(ProceedingJoinPoint pjp){
Object rtValue = null;
try {
System.out.println("前置通知");
Object[] args = pjp.getArgs();
rtValue= pjp.proceed(args);
System.out.println("后置通知");
return rtValue;
} catch (Throwable t) {
System.out.println("异常通知");
throw new RuntimeException(t);
}finally {
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">

<!--配置spring的ioc,把service对象配置进来-->
<bean id="accountService" class="com.hope.service.impl.AccountService"></bean>
<!--配置logger类-->
<bean id="logger" class="com.hope.utils.Logger"></bean>
<!--配置AOP-->
<aop:config>
<!--配置切面-->
<aop:aspect id="logAdvice" ref="logger">
<aop:pointcut id="pt1" expression="execution(* *..*.*(..))"/>
<!--配置通知的类型,并且建立通知方法和切入点方法的关联-->
<!--<aop:before method="printLog" pointcut="execution(public void com.hope.service.impl.AccountService.saveAccount())"></aop:before>-->
<!--<aop:before method="printLog" pointcut="execution(void com.hope.service.impl.AccountService.saveAccount())"></aop:before>-->
<!--<aop:before method="printLog" pointcut="execution(* com.hope.service.impl.AccountService.saveAccount())"></aop:before>-->
<!--<aop:before method="printLog" pointcut="execution(* *.*.*.*.AccountService.saveAccount())"></aop:before>-->
<!--<aop:before method="printLog" pointcut="execution(* *.*.*.*.AccountService.saveAccount())"></aop:before>-->
<!--<aop:before method="printLog" pointcut="execution(* *..AccountService.saveAccount())"/>-->
<!--<aop:before method="printLog" pointcut="execution(* *..*.*())"/>-->
<!--<aop:before method="beforePrintLog" pointcut-ref="pt1"/>-->
<!--<aop:after-returning method="afterReturningPrintLog" pointcut="execution(* *..*.*(..))"/>-->
<!--<aop:after-throwing method="afterThrowingPrintLog" pointcut="execution(* *..*.*(..))"/>-->
<!--<aop:after method="afterPrintLog" pointcut-ref="pt1"/>-->
<!--<aop:before method="printLog" pointcut="execution(* *..*.*(..))"/>-->
<aop:around method="aroundPrintLog" pointcut-ref="pt1"/>
</aop:aspect>
</aop:config>
</beans>


最新文章

  1. JQuery一些基础笔记
  2. 初识python面向对象
  3. HTML5自学笔记[ 10 ]简单的购物车拖拽
  4. openSUSE13.1 Yast 中所有软件图形化界面无法打开,问题原因: Ruby
  5. 三星 PMU NXE2000,x-powers的AXP228,NXE2000
  6. MySQL——修改root密码的4种方法(以windows为例)
  7. 一周学会Mootools 1.4中文教程:(6)动画
  8. java web面试
  9. 使用spine骨骼动画制作的libgdx游戏
  10. 基础总结(01)--css清除浮动几种方法
  11. CSS3动画属性:变形(transform)
  12. (第十三周)Final阶段用户调查报告
  13. 安装 RabbitMQ
  14. Java:foreach实现原理
  15. HDU 3333 Turing Tree(树状数组/主席树)
  16. unity3d 九宫密码锁
  17. 【Linux】数据流重导向(后篇)
  18. MySQL学习【第十篇存储引擎实际应用】
  19. 关于&lt;!DOCTYPE html&gt;
  20. (转帖)关于easyui中的datagrid在加载数据时候报错:无法获取属性&quot;Length&quot;的值,对象为null或未定义

热门文章

  1. 学习JS的第二天
  2. Springboot 启动分析
  3. 团队作业3--需求改进&amp;系统
  4. Django笔记&教程 3-2 模板语法介绍
  5. .NET6运行时动态更新限流阈值
  6. 利用Fastjson注入Spring内存马
  7. .net工程师学习vue的心路历程(三)
  8. 【性能优化】(2)JVM调优
  9. Jmeter——变量嵌套函数使用(__V)案例分析
  10. Atcoder Grand Contest 020 E - Encoding Subsets(记忆化搜索+复杂度分析)