spring aop自动代理xml配置
<?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> <bean id="count" class="com.zr.utils.Calculate"></bean>
<bean id="testAspect" class="com.zr.utils.TestAspect"></bean>
<aop:config>
<aop:aspect id="test" ref="testAspect">
<aop:pointcut id="calculate" expression="execution(* com.zr.utils.*.*(..))" />
<aop:before method="methodBefore" pointcut-ref="calculate"/>
<aop:after method="methodAfter" pointcut-ref="calculate"/>
<aop:after-returning method="methodAfterRunning" pointcut-ref="calculate" returning="result"/>
<aop:after-throwing method="methodAfterThrowing" pointcut-ref="calculate" throwing="exception"/>
</aop:aspect>
</aop:config> </beans>
package com.zr.utils;
public class Calculate implements Compute{
public int div(int num1,int num2){
System.out.println("除法");
return num1/num2;
}
}
package com.zr.utils;
import java.util.Arrays;
import org.aspectj.lang.JoinPoint;
public class TestAspect {
//第一个 * 代表任意修饰符及任意返回值,其中 .. 匹配任意数量的参数.
public void methodBefore(JoinPoint joinpoint){
System.out.println("执行方法:"+joinpoint.getSignature().getName()+"之前"+" 参数:"+Arrays.asList(joinpoint.getArgs()));
}
//第一个 * 代表public修饰符下任意返回值,第一个 * 代表com.zr.utils.Calculate路径下的任意方法
public void methodAfter(JoinPoint joinpoint) {
System.out.println("执行方法:"+joinpoint.getSignature().getName()+"之后");
}
//匹配第一个参数为 int 类型的方法, .. 匹配任意数量任意类型的参数
public void methodAfterRunning(JoinPoint joinpoint,Object result){
System.out.println("返回结果之后执行"+",返回结果:"+result);
}
//匹配参数类型为 int, int 类型的方法.
public void methodAfterThrowing(JoinPoint joinPoint,Exception exception){
System.out.println("异常通知, 在方法抛出异常之后执行"+",异常日志:"+exception);
}
}
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("count");
int result = c.div(10, 2); }
}
spring aop自动代理xml配置的更多相关文章
- spring aop自动代理注解配置之二
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...
- spring aop自动代理注解配置之一
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...
- 死磕Spring之AOP篇 - Spring AOP自动代理(一)入口
该系列文章是本人在学习 Spring 的过程中总结下来的,里面涉及到相关源码,可能对读者不太友好,请结合我的源码注释 Spring 源码分析 GitHub 地址 进行阅读. Spring 版本:5.1 ...
- 死磕Spring之AOP篇 - Spring AOP自动代理(三)创建代理对象
该系列文章是本人在学习 Spring 的过程中总结下来的,里面涉及到相关源码,可能对读者不太友好,请结合我的源码注释 Spring 源码分析 GitHub 地址 进行阅读. Spring 版本:5.1 ...
- 死磕Spring之AOP篇 - Spring AOP自动代理(二)筛选合适的通知器
该系列文章是本人在学习 Spring 的过程中总结下来的,里面涉及到相关源码,可能对读者不太友好,请结合我的源码注释 Spring 源码分析 GitHub 地址 进行阅读. Spring 版本:5.1 ...
- Spring Aop实例之xml配置
AOP的配置方式有2种方式:xml配置和AspectJ注解方式.今天我们就来实践一下xml配置方式. 我采用的jdk代理,所以首先将接口和实现类代码附上 package com.tgb.aop; pu ...
- Spring AOP 动态代理 缓存
Spring AOP应用:xml配置及注解实现. 动态代理:jdk.cglib.javassist 缓存应用:高速缓存提供程序ehcache,页面缓存,session缓存 项目地址:https://g ...
- 使用BeanNameAutoProxyCreator实现spring的自动代理
提到代理,我们可以使用ProxyBeanFactory,并配置proxyInterfaces,target和interceptorNames实现,但如果需要代理的bean很多,无疑会对spring配置 ...
- Spring AOP 注解和xml实现 --转载
AOP是OOP的延续,是Aspect Oriented Programming的缩写,意思是面向切面编程.可以通过预编译方式和运行期动态代理实现在不修改源代码的情况下给程序动态统一添加功能的一种技术. ...
随机推荐
- WCF OpenTimeout, CloseTimeout, SendTimeout, ReceiveTimeout
1.OpenTimeout 客户端与服务端建立连接时,如果超过指定时间都还没完成,就引发TimeoutException. 在TCP通讯中,服务器必须首先准备好侦听端口并在该端口上侦听(Listen) ...
- RESTful 服务示例
WCF服务轻量级服务,可供JS调用 返回值格式:XML.Json 工程结构: 示例代码: using System; using System.Collections.Generic; using S ...
- js删除局部变量的实现方法
lert('value:'+str+'\ttype:'+typeof(str)) //声明变量前,引用 var str="dd"; alert('value:'+str+'\tty ...
- 恢复所有情况的ip地址
在终端下输入一串ip字符串如:19219219211,ip地址可能是19.219.219.211.192.19.219.211.192.192.19.211和192.192.192.11. 以下是本人 ...
- qt的下载地址
上Qt官网http://www.qt.io/download/想下载Qt,速度很慢,在这里记录下在Qt官网看到的镜像下载地址: 1. 所有Qt版本下载地址: http://download.qt.io ...
- Avro之二:入门demo
一.使用avro-maven插件为avsc文件生成对应的java类: 在项目的pom.xml中增加依赖及插件如下: <dependency> <groupId>org.apac ...
- codeforces 985 D. Sand Fortress(二分+思维)
Sand Fortress time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- Java-Maven-Runoob:Maven构建生命周期
ylbtech-Java-Maven-Runoob:Maven构建生命周期 1.返回顶部 1. Maven 构建生命周期 Maven 构建生命周期定义了一个项目构建跟发布的过程. 一个典型的 Mave ...
- Unity3D的坑系列:打包Assetbundle丢失Shader问题(贴图显示不了)
从Unity4.2开始,为了减少首包大小,不会默认将所有Shader引擎加到游戏程序中,据Unity技术支持人员所说,Unity会将Shader引擎打包到Assetbundle资源中,但是我测试发现不 ...
- 一个7重嵌套表EF添加语句,注意子表赋值过程中只需写子表主键赋值,不需要写子表外键=父表主键。EF创建时会自动将子表外键设为与父表主键相等
AIRPORT_HELIPORT tt = new AIRPORT_HELIPORT() { AIRPORT_HELIPORT_UUID = Gui ...