<?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); }
}

spring aop自动代理注解配置之一的更多相关文章

  1. spring aop自动代理注解配置之二

    <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...

  2. spring aop自动代理xml配置

    <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...

  3. 死磕Spring之AOP篇 - Spring AOP自动代理(一)入口

    该系列文章是本人在学习 Spring 的过程中总结下来的,里面涉及到相关源码,可能对读者不太友好,请结合我的源码注释 Spring 源码分析 GitHub 地址 进行阅读. Spring 版本:5.1 ...

  4. 死磕Spring之AOP篇 - Spring AOP自动代理(三)创建代理对象

    该系列文章是本人在学习 Spring 的过程中总结下来的,里面涉及到相关源码,可能对读者不太友好,请结合我的源码注释 Spring 源码分析 GitHub 地址 进行阅读. Spring 版本:5.1 ...

  5. 死磕Spring之AOP篇 - Spring AOP自动代理(二)筛选合适的通知器

    该系列文章是本人在学习 Spring 的过程中总结下来的,里面涉及到相关源码,可能对读者不太友好,请结合我的源码注释 Spring 源码分析 GitHub 地址 进行阅读. Spring 版本:5.1 ...

  6. Spring AOP 动态代理 缓存

    Spring AOP应用:xml配置及注解实现. 动态代理:jdk.cglib.javassist 缓存应用:高速缓存提供程序ehcache,页面缓存,session缓存 项目地址:https://g ...

  7. 使用BeanNameAutoProxyCreator实现spring的自动代理

    提到代理,我们可以使用ProxyBeanFactory,并配置proxyInterfaces,target和interceptorNames实现,但如果需要代理的bean很多,无疑会对spring配置 ...

  8. Hibernate 延迟加载的代理模式 和 Spring AOP的代理模式

    Hibernate 延迟加载的代理模式 和 Spring AOP的代理模式 主题 概念 Hibernate 延迟加载的代理模式 Spring AOP的代理模式 区别和联系 静态代理和动态代理 概念 代 ...

  9. 运用Spring Aop,一个注解实现日志记录

    运用Spring Aop,一个注解实现日志记录 1. 介绍 我们都知道Spring框架的两大特性分别是 IOC (控制反转)和 AOP (面向切面),这个是每一个Spring学习视频里面一开始都会提到 ...

随机推荐

  1. phpcms URL修改

    修改caches\configs\system.php中'html_root' => 'html',//生成静态文件路径改成'html_root' => '',//生成静态文件路径,然后修 ...

  2. CodeForces - 662A:Gambling Nim (求有多少个子集其异或为S)(占位)

    As you know, the game of "Nim" is played with n piles of stones, where the i-th pile initi ...

  3. openfaas 架构介绍

     此为官方介绍   Overview of OpenFaaS Function Watchdog You can make any Docker image into a serverless fun ...

  4. 百度浏览器极速模式下访问 FastAdmin 的问题

    百度浏览器极速模式下访问 FastAdmin 的问题 兼容性问题,因为 https 证书配置时对低版本的浏览器不适配引起. 应该是 百度浏览器的内核太旧,没有更新导致.

  5. asp select count(*) 用 open还是excute

    dSql1="select count(*) from test_hist where uid="&cid  'dRs1.open dSql1,tConn,1,1  'dS ...

  6. bzoj 3796 Mushroom追妹纸——后缀数组

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3796 长度一般都是 1e5 ,看这个是 5e4 ,一看就是把两个串接起来做. 自己本来想的是 ...

  7. 避免Android内存泄露

    摘自:http://blog.csdn.net/xyz_lmn/article/details/7108011 Android的应用被限制为最多占用16m的内存,至少在T-Mobile G1上是这样的 ...

  8. gen_server的一些心得

    gen_server并不是我原来概念中的tcp_server或者udp_server的概念,只是一个纯粹的消息服务器,另外,附上它的一些回调函数的简单说明参考地址 http://hi.baidu.co ...

  9. angular 三大核心函数

    1.$watch  angular监听   由于angular一直在实时监听,所以比react和vue效率要低 $scope.$watch('aModel', function(newValue, o ...

  10. thinkphp中url的生成U()方法

    为了配合所使用的URL模式,我们需要能够动态的根据当前的URL设置生成对应的URL地址,为此,ThinkPHP内置提供了U方法,用于URL的动态生成,可以确保项目在移植过程中不受环境的影响.U方法的定 ...