能源项目xml文件标签释义--DefaultAdvisorAutoProxyCreator
[Spring]AOP拦截-三种方式实现自动代理
这里的自动代理,我讲的是自动代理bean对象,其实就是在xml中让我们不用配置代理工厂,也就是不用配置class为org.springframework.aop.framework.ProxyFactoryBean的bean。
用Spring一个自动代理类DefaultAdvisorAutoProxyCreator:
<bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator"></bean>
例如:
原来不用自动代理的配置文件如下:
<?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: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-4.3.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd"> <!-- 代理前原对象 -->
<bean id="person" class="cn.hncu.xmlImpl.Person"></bean> <!-- 切面 = 切点+通知 -->
<bean id="advisor" class="org.springframework.aop.support.RegexpMethodPointcutAdvisor">
<!-- 切点 -->
<property name="patterns">
<list>
<value>.*run.*</value>
</list>
</property>
<!-- 通知-由我们写,实际代理动作 -->
<property name="advice">
<bean id="advice" class="cn.hncu.xmlImpl.AroundAdvice"></bean>
</property>
</bean> <!-- 代理工厂 -->
<bean id="personProxied" class="org.springframework.aop.framework.ProxyFactoryBean">
<!-- 放入原型对象 -->
<property name="target" ref="person"></property> <!-- 放入切面 -->
<property name="interceptorNames">
<list>
<value>advisor</value>
</list>
</property>
</bean>
</beans>
现在改用自动代理,如下配置:
<beans ...>
<!-- 代理前原对象 -->
<bean id="person" class="cn.hncu.xmlImpl.Person"></bean> <!-- 切面 = 切点+通知 -->
<bean id="advisor" class="org.springframework.aop.support.RegexpMethodPointcutAdvisor">
<!-- 切点 -->
<property name="patterns">
<list>
<value>.*run.*</value>
</list>
</property>
<!-- 通知-由我们写,实际代理动作 -->
<property name="advice">
<bean id="advice" class="cn.hncu.xmlImpl.AroundAdvice"></bean>
</property>
</bean> <!-- 自动代理 -->
<bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator"></bean>
</beans>
测试方法
@Test//自动代理
public void demo4(){
ApplicationContext ctx = new ClassPathXmlApplicationContext("cn/hncu/xmlImpl/4.xml");
//我们直接在这里获取Person对象就可以了,因为在最开始xml文件newPerson对象后,Spring就已经帮我们代理了!
Person p =ctx.getBean(Person.class);
p.run();
p.say();
}
相对于前面,也就是把代理工厂部分换成自动代理了。
能源项目xml文件标签释义--DefaultAdvisorAutoProxyCreator的更多相关文章
- 能源项目xml文件标签释义--<context:component-scan>
<context:component-scan base-package="com.xindatai.ibs" use-default-filters="false ...
- 能源项目xml文件标签释义--default-lazy-init
1.spring的default-lazy-init参数 spring在启动的时候,会默认加载会默认加载整个对象实例图,从初始化ACTION配置.到 service配置到dao配置.乃至到数据库连接. ...
- 能源项目xml文件标签释义--CommonsMultipartResolver
<!-- 文件上传表单的视图解析器 --><bean id="multipartResolver" class="org.springframework ...
- 能源项目xml文件标签释义--DataSource
<bean id="dataSource1" class="org.apache.tomcat.jdbc.pool.DataSource" destroy ...
- 能源项目xml文件标签释义--<mvc:annotation-driven>
<mvc:annotation-driven />的可选配置 <mvc:annotation-driven message-codes-resolver ="bean re ...
- 能源项目xml文件 -- app-context.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...
- 能源项目xml文件 -- springMVC-servlet.xml -- default-lazy-init
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w ...
- 能源项目xml文件 -- app-dubbo.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...
- 能源项目xml文件 -- app-datasource.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...
随机推荐
- DevExpress所有的窗体,使用同一款皮肤
https://www.devexpress.com/Support/Center/Question/Details/K18516 To accomplish your task, please ex ...
- 【原创】OPA857 TEST模式使用
opa857 test mode: 配置opa857工作与test模式,设置tsst_sd为高电平连接到+Vs,test_in脚需要输入DC偏置以正确配置test模式.所需要增加的直流偏置大小因供电电 ...
- C#登录窗口及验证(+SQL)
团队成员及分工 团队: Blue 团队共有六人 姓名: 学号后四位: 贡献分: 张 宇(队长) 1152 1+1.7=2.7分 丁志愿 1 ...
- Java开发中经典的小实例-(随机数)
import java.util.Random;//输出小于33的7个不相同的随机数public class probability { static Random random = new R ...
- SpringMVC 模拟登陆
新建BackgroundController类: package cn.bdqn.mvc.controller; import org.springframework.stereotype.Contr ...
- CUBRID学习笔记 21 查看主键外键索引
命令 show create table game; game是表名 在web管理中,请在sql标签中查,不要在query中执行. show create table game; === <Re ...
- CUBRID学习笔记 12防火墙设置 linux
这玩意是linux上用的. 如果你的数据库不是装在linux下可以飘过了 iptables -I INPUT -p tcp --dport 8001 -j ACCEPT iptables -I INP ...
- CA*Layer(CATransformLayer--CAGradientLayer)
CATransformLayer CATransformLayer不同于普通的CALayer,因为它不能显示它自己的内容.只有当存在了一个能作用域子图层的变换它才真正存在.CATransformLay ...
- 函数(def)
一.为什么要使用函数: 面向过程的编程在代码里有很多代码是可以重复利用的,如果使用面向过程编程会使代码显得纷繁复杂,不利于他人和自己日后的阅读.而在函数式编程里,则可以把每个可重复利用的功能封装在一个 ...
- 2013年5月~2013年11月份(转接关于ns51服务平台项目)相关资料:
<1> [平台首页] 界面截图:(网络游客所看到的界面首页) <2>[注册] 有需求则注册会员(略...) <3>[个人空间] 注册成功后进入个人空间(有深层次的需 ...