<?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"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd "> <context:component-scan base-package="com.zr.utils"></context:component-scan> <!-- <aop:aspectj-autoproxy ></aop:aspectj-autoproxy> -->
<aop:aspectj-autoproxy proxy-target-class="true"></aop:aspectj-autoproxy>
</beans>
package com.zr.utils;

import org.springframework.stereotype.Component;

@Component("comp")
public class Calculate implements Compute{ public int div(int num1,int num2){
System.out.println("除法");
return num1/num2;
}
}
package com.zr.utils;

import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component; @Aspect
@Component("testAspect")
public class TestAspect { //第一个 * 代表任意修饰符及任意返回值,其中 .. 匹配任意数量的参数.
@Before("execution(* com.zr.utils.Calculate.div(..))")
public void methodBefore(){
System.out.println("执行方法之前");
}
//第一个 * 代表public修饰符下任意返回值,第一个 * 代表com.zr.utils.Calculate路径下的任意方法
@After("execution(public * com.zr.utils.Calculate.*(..))")
public void methodAfter() {
System.out.println("执行方法之后");
} //匹配第一个参数为 int 类型的方法, .. 匹配任意数量任意类型的参数
@AfterReturning("execution(public int com.zr.utils.Calculate.*(int,..))")
public void methodAfterRunning(){
System.out.println("返回结果之后执行");
}
//匹配参数类型为 int, int 类型的方法.
@AfterThrowing("execution(public int com.zr.utils.Calculate.*(int,int))")
public void methodAfterThrowing(){
System.out.println("异常通知, 在方法抛出异常之后执行");
}
}
package com.zr.utils;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; public class TestAop { public static void main(String[] args) { ApplicationContext ctc = new ClassPathXmlApplicationContext("context.xml"); /*Calculate calculate = (Calculate) ctc.getBean("comp");*/
Calculate c = (Calculate) ctc.getBean("comp");
int result = c.div(10, 2); }
}

最新文章

  1. Spring scope
  2. JMS笔记(一)
  3. C#中的线程二(BeginInvoke和Invoke)
  4. C编程风格.
  5. Material风格的Quick组件,妈妈再也不用担心我的界面不好看了
  6. 发布Activex全过程
  7. Python 清理HTML标签类似PHP的strip_tags函数功能(二)
  8. 用VSCode开发一个asp.net core 2.0+angular 5项目(4): Angular5全局错误处理
  9. 4. React 属性和状态介绍
  10. new/delete和malloc/free的比较
  11. Kafka~Linux环境下的部署
  12. golang与vscode的安装与配置
  13. 【leetcode-100】 简单 树相关题目
  14. Spark2.2出现异常:ERROR SparkUI: Failed to bind SparkUI
  15. 【RS】Collaborative Memory Network for Recommendation Systems - 基于协同记忆网络的推荐系统
  16. V-rep学习笔记:转动关节2
  17. D Tree Requests dfs+二分 D Pig and Palindromes -dp
  18. 【转载】MongoDB集群和实战详解
  19. linux系统查看IP地址,不显示IP地址或者只显示127.0.0.1
  20. 织梦(Dedecms) 5.1 feedback_js.php 注入漏洞

热门文章

  1. 关于15桥梁课程1&amp;2的笔记以及待做事项的梳理
  2. bzoj 4565 字符合并
  3. 有状态与无状态 cookie session
  4. linux离线搭建Python环境及安装numpy、pandas
  5. [CSU1911]Card Game
  6. latch的产生和消除
  7. Spring IOC容器的初始化—(一)Resource定位
  8. PCBA 的收货要求记录
  9. 转: 使用Jmeter创建ActiveMQ JMS POINT TO POINT请求,环境搭建、请求创建、插件安装、监听服务器资源等
  10. classpath和环境变量设置