spring通过代理工厂创建代理对象

学习spring有几天了,感觉自己对aop掌握不是很熟,自己就写了几个test


<?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"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<!--初识笔记:property 中的name代表的是上层bean(类)中的filed (filed可以理解为字段,或者是说此处的filed应该是某个类的对象
 【private AdminBean adminBean;】 ),当然要ref(关联)就必须有setXXX-->
<!--目标对象-->
<bean id="personService"  class="org.xiaoyi.service.impl.PersonServiceImpl"></bean>

<bean id="adminbean"  class="org.xiaoyi.bean.AdminBean"></bean>     <!--ioc管理,包含纯洁的权限验证方法-->
<bean id="logbean"  class="org.xiaoyi.bean.LogBean"></bean> <!--ioc管理,包含纯洁的记录日志方法-->


<!--权限验证前置通知-->

<bean id="adminInterceptor"  class="org.xiaoyi.interceptor.AdminInterceptor">     

                            <!--ioc管理,implements MethodBeforeAdvice,使该类变成前置通知类,其中有before(Methodmethod,Object[] args, Object   target){}-->

<property name="adminBean"  ref="adminbean"></property>              <!--关联 bean:adminbean ,作用是:为了在通知方法before()中调用关联bean的权        限验证-->
</bean>

<!--日志记录的后置通知-->
<bean id="logInterceptor"  class="org.xiaoyi.interceptor.LogInterceptor">   <!--implements AfterReturningAdvice-->
<property name="logBean"  ref="logbean"></property>
</bean>

<!--通过代理工厂创建代理对象-->
<bean id="targetProxy"  class="org.springframework.aop.framework.ProxyFactoryBean">     <!--ioc管理spring自己的类,其作用在于把通知和业务绑定,使其作 为一个代理,让通知和业务形成一个整体,升华后就是事物-->
<!--代理目标-->
<property name="target"  ref="personService"></property> <!--关联personService,作用是:为了在创建代理的时候让代理得到personService中的业务 方法-->
<!--代理的接口-->
<property name="proxyInterfaces"  value="org.xiaoyi.service.PersonService"></property>  <!--从事物的底层来看,上面已经关联personService,它就 应该拿的到对应的接口( ps.getClass().getInterfaces())
,此处又把接口传过去。。。不理解,也许是spring底层需要 -->
<!--代理通知-->
<property name="interceptorNames">     <!--实施绑定-->
<list>
<value>adminInterceptor</value>
<value>logInterceptor</value>
</list>
</property>
</bean>

</beans>

虽然3.0以上的spring版本多了很多新的特新,支持泛型,支持注解。。。

对于注解的方式,我想现在虽然趋于普遍,但是对于原理一定还是要了解清楚,毕竟对底层越熟,人生的机会越多。

在此,仅以本人的学习理解记录下来

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值